A
ake
I have the following code I tried to use to create Pivot table.
Sub CreatePivotTable()
Dim PTCache As PivotCache
Dim PT As PivotTable
Worksheets.Add
ActiveSheet.Name = "PivotSheet"
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=Range("A1").CurrentRegion.Address)
Set PT =
PTCache.CreatePivotTable(TableDestination:=Sheets("PivotSheet").Range("A1"),
TableName:=" PivotTable")
With PT
..PivotFields("Month").Orientation = xlPageField
..PivotFields("Control Number").Orientation = xlColumnField
..PivotFields("Company Code").Orientation = xlRowField
..PivotFields("Tax Payments").Orientation = xlDataField
End With
End Sub
It gives me "error 1004" and highlights the line:
Set PT =
PTCache.CreatePivotTable(TableDestination:=Sheets("PivotSheet").Range("A1"),
TableName:=" PivotTable")
What have I done wrong?
Sub CreatePivotTable()
Dim PTCache As PivotCache
Dim PT As PivotTable
Worksheets.Add
ActiveSheet.Name = "PivotSheet"
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=Range("A1").CurrentRegion.Address)
Set PT =
PTCache.CreatePivotTable(TableDestination:=Sheets("PivotSheet").Range("A1"),
TableName:=" PivotTable")
With PT
..PivotFields("Month").Orientation = xlPageField
..PivotFields("Control Number").Orientation = xlColumnField
..PivotFields("Company Code").Orientation = xlRowField
..PivotFields("Tax Payments").Orientation = xlDataField
End With
End Sub
It gives me "error 1004" and highlights the line:
Set PT =
PTCache.CreatePivotTable(TableDestination:=Sheets("PivotSheet").Range("A1"),
TableName:=" PivotTable")
What have I done wrong?