Find out what column pivot table heading is in

excelio

New Member
Joined
Oct 30, 2017
Messages
1
[FONT=&quot]Hi,[/FONT]
[FONT=&quot]I have a pivot table that has a number of values including revenue and volume and filters on a date range.[/FONT]
[FONT=&quot]The issue is if I change the date range the column called [/FONT]
[TABLE="width: 97"]
<tbody style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;">[TR]
[TD="width: 97"]Total Revenue
[/TD]
[/TR]
</tbody>[/TABLE]
[FONT=&quot]Also changes. I am requiring a way to find out what column the Total Revenue is in to then use in a count statement.[/FONT]
[FONT=&quot]Thanks[/FONT]
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this:

Code:
Option Explicit

Sub FindTermInPTColumnHeaders()
    
    'Assumption: Activesheet contains the pivot table
    'Assumption: The first PT on teh activesheet is the one to be examined
    'Assumption: the whitespace in your search term is a space
    'ActiveSheet.PivotTables(1).ColumnRange will limit find to the column header area\

    Const sFind As String = "Total Revenue"
    Dim oFound As Object
    Dim lColumn As Long
    
    Set oFound = ActiveSheet.PivotTables(1).ColumnRange.Find(What:=sFind, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    If Not oFound Is Nothing Then
        lColumn = oFound.Column
    End If
    
    If lColumn = 0 Then
        MsgBox "'" & sFind & "' was not found in your PT Column Headers"
    Else
        MsgBox lColumn & " is the column containing '" & sFind & "' in the column headers."
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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
Back
Top