I successfully made a macros in excel 2016, for creating a pivot table but I need to replicate the code for excel 2010. Copying over the code from the 2016 version into the 2010 doesn't work and I've also tried re-writing the code, to no avail. I don't understand what I'm doing wrong.
Here's the excel 2016 version that works perfect
now here's my adaption for the 2010 version, that isn't working
here's the compiler errors I'm getting:
"Name argument not found" highlighting
I get the following
"Run-time error '1004': Method 'Range' of object '_Global' failed"
highlighting the PTCache variable again.
Here's the excel 2016 version that works perfect
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#303336]Sheets[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Add
ActiveWorkbook[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotCaches[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Create[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]SourceType[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]xlDatabase[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] SourceData[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336] _
[/COLOR][COLOR=#7D2727]"Superbills!R1C1:R563C86"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Version[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]6[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]CreatePivotTable TableDestination[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336] _
[/COLOR][COLOR=#7D2727]"Sheet1!R3C1"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] TableName[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] DefaultVersion[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]6[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
Cells[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]3[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Practice Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Provider Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]2[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Full Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]3[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]AddDataField ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] _
[/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Entry Date"[/COLOR][COLOR=#303336]),[/COLOR][COLOR=#7D2727]"Count of Entry Date"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] xlCount
ActiveCell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Offset[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]0[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Practice Name"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]ShowDetail _
[/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Name [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"Pivot Table"[/COLOR]</code>
now here's my adaption for the 2010 version, that isn't working
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Dim[/COLOR][COLOR=#303336] PTCache [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] PivotCache
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] PT [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] PivotTable
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] PTCache [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] ActiveWorkbook[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotCaches[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Create[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]SourceType[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]xlDatabase[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] _
SourceData[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]Range [/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Superbills!R1C1:R563C86"[/COLOR][COLOR=#303336]))[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
Cells[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]3[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] PT [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Add[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]PivotCache[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]PTCache[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] _
TableDestination[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1!R3C1"[/COLOR][COLOR=#303336]),[/COLOR][COLOR=#303336] TableName[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
ActiveWorkbook[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]ShowPivotTableFieldList [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]True[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Practice Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Provider Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]2[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Full Name"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Orientation [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] xlRowField
[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Position [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]3[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]With[/COLOR][COLOR=#303336]
ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]AddDataField ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336] _
[/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Entry Date"[/COLOR][COLOR=#303336]),[/COLOR][COLOR=#7D2727]"Count of Entry Date"[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] xlCount
ActiveCell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Offset[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]0[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]PivotTables[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"PivotTable1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]PivotFields[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Practice Name"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]ShowDetail _
[/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#101094]Select[/COLOR][COLOR=#303336]
Sheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Sheet1"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Name [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]"Pivot Table"[/COLOR]</code>
"Name argument not found" highlighting
(Version:=6) in PTCache variable.
once that's removed.
I get the following
"Run-time error '1004': Method 'Range' of object '_Global' failed"
highlighting the PTCache variable again.
Code:
[INDENT]Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _ SourceData:=Range("Superbills!R1C1:R563C86"))
[/INDENT]