I'm trying to create custom reports using VBA created pivot tables and one of the parts I am having trouble with is setting the datafield to be based on what he user desires.
For example: I have a drop down menu that displays each type of PivotFields function (sum, min max etc.) and depending on what the user selects it is stored as a string variable.
When I run my code:
Dim valueXL As String
valueXL = xlSum
With Worksheets(sheetPivotName).PivotTables(sheetPivotName).PivotFields(valueType)
.Function = valueXL
.NumberFormat = "$#,##0.00"
End With
I get an error, however, if I replace .Function = valueXL with .Function = xlSum it works correctly.
Is there any way to dynamically set the .Function value?
Thanks