PivotTable CurrentPage

G

Guest

I am trying to return the displayed page name of a pivottable. The code that
I have been using is as follows:

Function PvtTablePageName(ByVal pvtTable As PivotTable) As String

Dim pgName As String
Dim pt As PivotTable
Set pt = Worksheets("Sheet1").PivotTables(pvtTable)
pgName = pt.PivotFields("Account #").CurrentPage.Name
PvtTablePageName = pgName

End Function

This returns a #VALUE error. Any help would be appreciated.

Regards,
Mark
 
T

Tom Ogilvy

I assume you are passing in the Pivot Table name as a string.

Function PvtTablePageName(ByVal pvtTable As String) As String
'comment out the next line if this is not used in a worksheet cell
Application.Volatile
Dim pgName As String
Dim pt As PivotTable
Set pt = Worksheets("Sheet1").PivotTables(pvtTable)
pgName = pt.PivotFields("Account #").CurrentPage.Name
PvtTablePageName = pgName

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top