Get the Current Row Using VBA

Sometimes you may want to write a macro that identifies the active row in your spreadsheet. This tutorial shows you how to get the current row in a spreadsheet using Excel VBA.

How to get the current row in a worksheet using Excel VBA

We will use the following data set in our illustration.

We use the following steps:

  1. Open the worksheet that contains the data set.
  2. In the active worksheet press Alt + F11 to open the Visual Basic Editor.
  3. Click Insert >> Module to create a new module.
  1. Type the following sub-procedure in the module.
Public Sub ActiveRow()
  MsgBox "The current row is row " & ActiveCell.Row
End Sub 
  1. Save the procedure and save the workbook as an Excel Macro-Enabled workbook.
  2. Place the cursor anywhere in the procedure and press F5 to run the code.

A message box pops up in the active worksheet showing that row 6 is the current row. Note that row 6 is the current row because the cell selector is in cell A6.

Conclusion

This tutorial has demonstrated how to get the current row in a worksheet using Excel VBA.

Posted in vba