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
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
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.
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
In this way, you can get the row number of the selected cell, using VBA code.
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.