Excel VBA: Getting the Row Number of an Active Cell

Sometimes, we need to get a row number of the current active cell.

Macro Examples

The following Excel VBA macro displays the row number of the active cell in a message box.

Sub GetActiveCellRowNumber()

  MsgBox ActiveCell.Row

End Sub

Description

ActiveCell property

  ActiveCell...

The Application.ActiveCell property returns the active Range object that represents the only current active cell.

obj-Excel-Application-ActiveCell

And, the ActiveCell property is a member of the Excel.Global class.

obj-Excel-Global-ActiveCell

So, we can omit the Application property.

Range.Row property

  ActiveCell.Row

The Range.Row property (ActiveCell.Row) returns the row number of the Range object.

obj-Excel-Range-Row

MsgBox function

The code: ActiveCell.Row is set to the parameter of a MsgBox function.

Sub GetActiveCellRowNumber()

  MsgBox ActiveCell.Row

End Sub

So, a message box shows the row number of an active cell.

Properties

http://www.relief.jp/itnote/archives/excel-vba-get-row-number.php

Apply to

  • Excel 2013
  • Excel 2010
  • Excel 2007