Excel VBA: Getting a Table Header Row Address

This Excel VBA macro shows a message box with a table header row address.

Macro Example

Sub GettingTableHeaderRowAddress()

  MsgBox ActiveSheet.ListObjects(1).HeaderRowRange.Address(False, False)

End Sub

Description

[Application.]ActiveSheet

  ActiveSheet...

The [Application.]ActiveSheet property returns an active Worksheet or Chart object. So the Object Browser shows us that returned value is “Object”.

obj-Excel-Application-ActiveSheet

The ActiveSheet property is a member of the Excel.Global class, so we can omit the Application property.

obj-Excel-Global-ActiveSheet

ActiveSheet.ListObjects (Worksheet.ListObjects)

  ActiveSheet.ListObjects...

The ActiveSheet.ListObjects (Worksheet.ListObjects property) returns a ListObjects collection object on the active worksheet.

obj-Excel-Worksheet-ListObjects

ListObjects(1) (ListObjects._Default(1) )

  ActiveSheet.ListObjects(1)...

The ListObjects._Default property returns a single ListObject object from a ListObjects collection object.

obj-Excel-ListObjects-_Default

And the ListsObjects._Default(1) represents the first ListObject object.

The _Default property is a default member of the ListObjects collection object. We can see a little blue marble beside its icon in the Object Browser.
So we can omit the ._Default .

ListObjects(1).HeaderRowRange (ListObject.HeaderRowRange)

  ActiveSheet.ListObjects(1).HeaderRowsRange...

The ListObjects(1).HeaderRowRange (ListObject.HeaderRowRange property) returns a Range object that represents the range of the header row to which the specified ListObject object.

obj-Excel-ListObject-HeaderRowRange

HeaderRowsRange.Address (Range.Address)

  ActiveSheet.ListObjects(1).HeaderRowsRange.Address...

The HeaderRowsRange.Address (Range.Address property) returns a String value that represents the range reference.

obj-Excel-Range-Address

  ActiveSheet.ListObjects(1).HeaderRowRange.Address(False, False)

By setting the arguments to False, False, the Range.Address property returns the string without $ signs.

Sub GettingTableHeaderRowAddress()

  MsgBox ActiveSheet.ListObjects(1).HeaderRowRange.Address(False, False)

End Sub

Properties

http://www.relief.jp/itnote/archives/excel-vba-getting-table-header.php

Apply to

  • Excel 2013
  • Excel 2010
  • Excel 2007