Pivot table range

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi everyone

I have syntax error on the code below. I can't find out the problem, please could anyone help?

Code:
Sheets("Combined Report - Modules").Select
Dim Last_Row As Long
Last_Row = Range("A" & Rows.Count).End(xlUp).Row

 ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Combined_Data!R1C1:R" & Last_Row & "C13", Version:=xlPivotTableVersion14).CreatePivotTable_
        TableDestination:="Combined Report - Modules"!R3C1", TableName:="PivotTable1", DefaultVersion_
        :=xlPivotTableVersion14

Also, is there a difference of the PivotTableVersion14 or 15? Many thanks.
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
For the version, see https://msdn.microsoft.com/en-us/li...ce.interop.excel.xlpivottableversionlist.aspx
I use Excel 2013 so my macros use xxlPivotTableVersion15

I found that defining a range variable outside the statement can work best and helps limit or pinpoint certain errors.
If "PivotTable1" already exist, I think it will error out. Its been so long since I wrote mine. If I remember correctly, I let mine error out because it stops the macro preventing the existing PivotTable from being destroyed.
Also, I use a more meaningful name for my PivotTables, especially when I've taken the time to write a macro.
 
Upvote 0
Thanks. I have updated the code but it still doesn't work. The syntax error highlighted the := after Tabledestination:

Code:
 ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Combined_Data!R1C1:R" & Last_Row & "C13", Version:=xlPivotTableVersion15).CreatePivotTable_
        TableDestination:=Worksheets("Combined Report - Modules"!R3C1", TableName:="ByModule", DefaultVersion _
        :=xlPivotTableVersion15
 
Upvote 0
Something seems off about the flow of that text and the exclamation point....
See how the macro recorder ends recording that reference and use in your code.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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