Excel VBA determine if ActiveCell is Table Header

JeannetteE

New Member
Joined
May 19, 2016
Messages
49
Hi,

"If ActiveCell.ListObject.Header Then"

I want to do something different if the Active Cell is the Header than if it isn't.

I have many tables and the Header Name is different for all of them.

Any help appreciated
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

gallen

Well-known Member
Joined
Jun 27, 2011
Messages
2,006
Hello, You just need to use intersect:

Code:
    If Not Intersect(ActiveCell, Me.ListObjects("[COLOR=#ff0000]YOURTABLENAME[/COLOR]").HeaderRowRange) Is Nothing Then
        'Active cell is a header
    Else
        'Active cell isn't a header
    End If
 
Last edited:

JeannetteE

New Member
Joined
May 19, 2016
Messages
49
Hello, You just need to use intersect:

Code:
    If Not Intersect(ActiveCell, Me.ListObjects("[COLOR=#ff0000]YOURTABLENAME[/COLOR]").HeaderRowRange) Is Nothing Then
        'Active cell is a header
    Else
        'Active cell isn't a header
    End If

Thank you for the response. I'm getting an "Invalid use of me word" Error
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
Try this.
Code:
Dim lst As ListObject

    Set lst = ActiveCell.ListObject
    
    If lst Is Nothing Then
        MsgBox "Active cell not in table."
    Else
        If Not Intersect(lst.HeaderRowRange, ActiveCell) Is Nothing Then
            MsgBox "Active cell is in table header."
        End If
    End If
 

Watch MrExcel Video

Forum statistics

Threads
1,130,119
Messages
5,640,218
Members
417,131
Latest member
Seanr19871

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top