I am creating a VBA macro. Among other things, it makes a pivot table:
With Worksheets("Working")
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
lColumn = .Range("A" & .Columns.Count).End(xlToLeft).Column
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=.Range(.Cells(1, 1), .Cells(lRow, lColumn))).CreatePivotTable TableDestination:="", TableName:="HDPivotTable", DefaultVersion:=xlPivotTableVersion10
End With
ActiveSheet.Name = "HD Pivot"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(1, 1)
ActiveSheet.PivotTables("HDPivotTable").AddFields RowFields:="Location Code"
For some reason, I am getting Run-time error '1004': AddFields method of PivotTable class failed
Could you please help?
Question related to this previous question.
Thanks