Run Time Error 5 - Macro for Pivot Table

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
74
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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