I don't understand how to make this code work. Any help would be appreciated.
I can create a Pivot Table with the wizard just fine, but with the following code...
I just get the following error when Excel tries to SET PT = ....
I can create a Pivot Table with the wizard just fine, but with the following code...
Code:
Sub NewPivotTable()
'
' NewPivotTable Macro
'
Dim PTSheet As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Variant
Sheets.Add
ActiveSheet.name = "Pivot"
Set PTSheet = Worksheets("Pivot")
Set PRange = Sheets("temp").Range("PivotData")
' MsgBox PRange.Address
Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:="'" & PTSheet.name & "'!" & PRange.Address(, , xlR1C1), _
Version:=xlPivotTableVersion12)
Set PT = PTCache.CreatePivotTable(TableDestination:="'Pivot'!R3C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12)
End Sub
I'm using Excel 2007 on WinXPError said:Run-time error '1004':
The PivotTable field name is not valid. To create a PivotTable report, you must use data that is organized as a list with labeled columns. If you are changing the name of a PivotTable Field, you must type a new name for the field.