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]
Total Revenue

<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;">
</tbody>
[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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

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