Hi,

I would appreciate any advice to make the following pivot table macro work. Using the macro recorder, I created a macro to hide a "value" pivot field and show a "quantity" pivot field. The macro works fine if I switch from quantity to value and vice versa. But if I am in the quantity field and run the "quantity" macro again, it shows the error message: "Unable to get the PIvotfields property of the pivot table class". The macro below shows the code to hide the "value" pivot field in order to show the quantity pivot field. What I understand from the message is that, because the "quantity" pivotfield is already selected, the macro does not know what to do unless it is instructed as follow: "If the quantity pivot field is already selected, do nothing". How can I write this piece of code?

By_quantity_group Macro
'
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveSheet.PivotTables("PivotTable3").PivotFields("Sum of Sales MTD Sales"). _
Orientation = xlHidden
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Sales QTY-MTD"), "Sum of Sales QTY-MTD", xlSum
End Sub

Thanks