I am beyond frustrated with this, and desperately need help. I have used this code before in other workbook with no problem. Tried to copy it over, replacing the variables and workbook-specific information for the new file, only to run into this stupid error (on the line containing 'Set objPT = ...'). I even tried copying code directly out of an Excel VBA textbook for creating a pivot table and still ran into the same stupid error. I cannot figure out what I am doing wrong.
Sub SetupPivotTable()
Dim PTWS As Worksheet
Dim objPT As PivotTable
Dim objPC As PivotCache
Range("Q3").Activate
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
bottomRow = Selection.Address
' MsgBox bottomRow
Range("A3", bottomRow).Select
Selection.Name = "UTS_Data"
Sheets.Add After:=Worksheets(Worksheets.Count)
Set PTWS = ActiveSheet
ActiveSheet.Name = "Graph"
Sheet1.Activate
Set objPC = ActiveWorkbook.PivotCaches.Create _
(xlDatabase, "UTS_Data")
Set objPT = objPC.CreatePivotTable(PTWS.Range("a3"), _
TableName:="UTS_PT")
End Sub
Alternatively, I tried using this:
Set objPT = objPC.CreatePivotTable _
TableDestination:="'Graph'!R3C1", TableName:="UTS_PT"
And it instead errored out with 'Expected End of Statement' on 'TableDestination'
There is more to this macro, but this is all that's relevant for the current problem.