How to Find Row Number of Active Cell For VBA

Updated February 21, 2017

Visual Basic for Applications (VBA) is a subset of the programming language Visual Basic. VBA is used exclusively in Microsoft Office applications like Word, PowerPoint and Excel. If you are using VBA in Excel, you may want to write a macro, or executable code, that references the row number that the active cell is on--the active cell is the cell where the cursor is currently placed. A short piece of code will tell you the active cell's row number.

Press "Alt" and "F11" together from inside the worksheet where you want to find the active cell's row number. This action opens the Visual Basic Editor (VBE).

Click "Insert" and then click "Module" to open a blank module window.

Cut and paste the following code into your worksheet:

Sub RowNum()

MsgBox "The active cell row is " & ActiveCell.Row

End Sub

Press "F5" to run the routine. The macro will return the active cell's row in a message box.


You can also access the VBE by clicking "Developer" and then "Visual Basic."

Things You'll Need

  • Excel 2010 or Excel 2007
Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Stephanie Ellen teaches mathematics and statistics at the university and college level. She coauthored a statistics textbook published by Houghton-Mifflin. She has been writing professionally since 2008. Ellen holds a Bachelor of Science in health science from State University New York, a master's degree in math education from Jacksonville University and a Master of Arts in creative writing from National University.