Pivot Table VBA

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,059
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have the code below and its showing me the error as "Invalid Procedure call or argument"

Set pt = ActiveSheet.PivotTables.Add(PivotCache:=PCache, _
TableDestination:=Range("A1"), TableName:="PivotTable1") this code is the error



VBA Code:
Sub Pivot()
Dim PCache As PivotCache, pt As PivotTable, rs As Worksheet

On Error Resume Next
Application.DisplayAlerts = False
Sheets("Pivot").Delete
On Error GoTo 0
Application.DisplayAlerts = True

Set rs = Sheets("Sheet3")
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, _
SourceData:=rs.Range("A1").CurrentRegion.Address)


Worksheets.Add
ActiveSheet.Name = "Pivot"
ActiveWindow.DisplayGridlines = False
Set pt = ActiveSheet.PivotTables.Add(PivotCache:=PCache, _
TableDestination:=Range("A1"), TableName:="PivotTable1")
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
There's nothing inherently wrong with the code syntax. Where is it located - i.e. which module?
 
Upvote 0
If it's in a worksheet code module, then change the destination argument to specify the sheet:

Rich (BB code):
TableDestination:=Activesheet.Range("A1")
 
Upvote 0
yes got it, I have put the code in module and it is all well, thanks. my miss. :)
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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