I'm very new to VBA but I know how to record macros and I tried doing that for a report I run monthly. In the report, I make a pivot table of some data to sum up the data by country. I then highlight the pivot table and paste it below the current pivot table to create a second pivot table and go from there summing up the data by customer and adding in a whole bunch of other stuff. The macro keeps getting hung up on the first reference to the new pivot table when I run it and I'm not sure why. I tried changing the activesheet.pivottables part to sheets("sheet1") to actually reference the sheet I'm working in as some post online recommended but it still got hung up.
Below is the code where it's getting stuck. I'm assuming the issue is that it can't find pivottable2 for some reason but I don't know why or how to name a pivot table in the middle of code much less how to change all the following code after this section that refers to it as ActiveSheet.PivotTables("PivotTable2"). Any help is appreciated
Range("A1:E11").Select
Selection.Copy
Range("A18").Select
ActiveSheet.Paste
With Sheets("Sheet1").PivotTables("PivotTable2").PivotFields("Customer") <----- highlights this line as the issue.
.Orientation = xlRowField
.Position = 1
End With
NEVERMIND I JUST DISCOVERED FOR SOME REASON THE PASTED PIVOT TABLE IS LABELED PIVOTTABLE3 FOR SOME REASON. I WOULD DELETE THIS IF I COULD.
Below is the code where it's getting stuck. I'm assuming the issue is that it can't find pivottable2 for some reason but I don't know why or how to name a pivot table in the middle of code much less how to change all the following code after this section that refers to it as ActiveSheet.PivotTables("PivotTable2"). Any help is appreciated
Range("A1:E11").Select
Selection.Copy
Range("A18").Select
ActiveSheet.Paste
With Sheets("Sheet1").PivotTables("PivotTable2").PivotFields("Customer") <----- highlights this line as the issue.
.Orientation = xlRowField
.Position = 1
End With
NEVERMIND I JUST DISCOVERED FOR SOME REASON THE PASTED PIVOT TABLE IS LABELED PIVOTTABLE3 FOR SOME REASON. I WOULD DELETE THIS IF I COULD.