How to Find Row Number of Active Cell For VBA


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.

Things You'll Need

  • Excel 2010 or Excel 2007
  • 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.

Tips & Warnings

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

Related Searches


  • Photo Credit Jupiterimages/Comstock/Getty Images
Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!