|re: I created a command to change the current worksheet to "Demand Pivot" and then changed "PivotTables5" to "Demand Pivot"|
The RepeatAllLabels instruction is not looking for the name of the worksheet, it is looking for the name of the Pivot Table.
To explain what I mean, look at this instruction:
Notice how it is Selecting the sheet by its Name: Sheets("Demand")
Now look at this Instruction:
Notice how it is referencing a Pivot Table by its Name: PivotTables("PivotTable5")
Changing the name of the Sheet does not change the Name of the Pivot Table.
Whenever an object is created in Excel, Excel gives it a name. It doesn't matter if it's a Sheet, a picture, a shape, a Pivot Table, etc. Every object has a Name and you can access that object within VBA by that Name. You can also access the Object by a number, if you know which Pivot Table it is.
If the Pivot Table that you are trying to access is the only one on the sheet, then it might be Pivot Table #1 and this instruction might work.
Notice that I replaced the Name "PivotTable5" with the number 1.
A Name must be a text string enclosed in quotes, but a number is the actual number by which VBA knows the object.
PivotTables("PivotTable1") may or may not be the same object as PivotTables(1). "PivotTable1" is just a Name. You could name that Pivot Table "Fred" or "Sales" or "Revenue" and it would still retain its number within Excel.
Since I can't actually test your code without a copy of your workbook, that is the best I can offer at this point.
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.