Apple08

Active Member
Joined
Nov 1, 2014
Messages
353
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:

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

SpillerBD

Well-known Member
Joined
Jul 2, 2014
Messages
2,707
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.
 

Apple08

Active Member
Joined
Nov 1, 2014
Messages
353
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
 

SpillerBD

Well-known Member
Joined
Jul 2, 2014
Messages
2,707
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,335
Messages
5,528,096
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top