Run Time Error 5 - Macro for Pivot Table

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
I'm not the greatest with macros and I generally use the record a macro and play around with it until it does what I want. I recorded creating a pivot table, placing it in an existing sheet and when I delete the pivot table and try to run the macro again to confirm it works, I am receiving a Run Time Error 5, invalid procedure call or argument.

Here is my code:
Range("A1:U7591").Select
VBA Code:
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Firm Listing!R1C1:R7591C21", Version:=15).CreatePivotTable TableDestination _
        :="my-benefits!R1C1", TableName:="PivotTable6", DefaultVersion:=6
    Sheets("my-benefits").Select

Anyone know what I'm doing wrong? I also want to make the row count automatic, as it changes every month when I do my reporting. It will always be column U, but a different row number.

Any help is greatly appreciated!
 
Also, if your headers are in row 1, you need to include that row in the source data.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,214,551
Messages
6,120,159
Members
448,948
Latest member
spamiki

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