PivotTable Name

MikeDBMan

Well-known Member
Joined
Nov 10, 2010
Messages
608
The last line of code below errors out. What is the proper syntax for getting the name of the pivot table that is in A2?


Code:
Sub GetPTName
Dim PTCache As PivotCache, PT As PivotTable
Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,SourceData:=Range("A2").CurrentRegion)

Set PT = ActiveSheet.PivotTables.Name
end sub
 

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.
Hey,

this is what I am using in mine at the moment.
ActiveSheet.PivotTables("PivotTable1")

you can then add:
ActiveSheet.PivotTables("PivotTable1").PivotFields("pivotfieldfield") more added functionality.

Hope this helps.
 
Upvote 0
It would be just:
Code:
Range("A2").PivotTable.Name
 
Upvote 0
Rory,
So I've tried doing Let PT=range("A2).PivotTable.name and I get "Unable to get the PivotTable property of the Range class.

I've tried Set PT (with PT dimmed as PivotTable) and Let PT (With PT DImmed as string). Neither works.

And cainey, it is not PivotTable1, I can see that when I check manually.

What I want to do is assign a slicer to the pivot table. I think I need the name and then hopefully I can issue this code: (Where PT is the variable name I assigned from the code I can't figure out.
Code:
    ActiveWorkbook.SlicerCaches.Add(ActiveSheet.PivotTables(PT), _
        "CC Description").Slicers.Add ActiveSheet, , "CC Description", "CC Description" _
        , 207.75, 450, 144, 198.75
 
Upvote 0
Then A2 is not part of a pivot table. (From the code it looks like it's part of the source data)

Also, you can't assign the name of a pivot table, which is just a String, to a PivotTable object variable.
 
Upvote 0
So how can I add a slicer to an existing pivot table? I can't seem to figure out how to do it.
 
Upvote 0
In code or manually?
 
Upvote 0
Then A2 is not part of a pivot table. (From the code it looks like it's part of the source data)

Also, you can't assign the name of a pivot table, which is just a String, to a PivotTable object variable.

Isnt pivot table and source data the same thing? Ie the source data makes the pivot table so when you say a2 is not part of the pivot but source, I'm not quite sure what you mean. I thought it was the same
 
Upvote 0
The pivot table is the graphical summary of the source data - the two can't be in the same place.
 
Upvote 0
In code or manually?

I want to do it within VBA. And I need multiple versions of the same pivottable on different tabs. It seems if I have the PivotTable with a slicer on a tab and then duplicate that entire tab and change the slicer, it changes the slicer on the first tab, not the newly-copied tab. I can live with that but it is a little hard to work with.
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,748
Members
449,335
Latest member
Tanne

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