How To Get Row Number By A Single Click Using VBA In Microsoft Excel 2010

In this article, you will learn how to get row number by a single click.

 

Click on Developer tab
From Code group, select Visual Basic
 
img1
 
Enter the following code in the current worksheet (sheet1 in our example)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim rownumber As Integer

rownumber = ActiveCell.Row

    If ActiveCell.Value <> “” Then

        MsgBox “You have clicked on row number ” & rownumber

    End If

End Sub
 
img2
 
The SelectionChange event will get activated every time the user selects any cell & it will give us the row number of the selected cell. If active cell is empty then, the code will not run.
 
img3
 
In above snapshot, you can see the formula bar contains cell D4 & hence the row number is 4.

If we select cell A1, and then we get the row number as 1. Refer below shown snapshot
 
img4
 
In this way, you can get the row number of the selected cell, using VBA code.
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube