I have the following sub:
Sub test()
DeviceModel = "123 Model_name"
ActiveSheet.PivotTables(DeviceModel).PivotFields("Baseline Release").AutoSort _
xlDescending, "Count of Device ID"
ActiveSheet.PivotTables(DeviceModel).PivotFields("Baseline Release"). _
PivotFilters.Add Type:=xlValueIsGreaterThan, DataField:=ActiveSheet. _
PivotTables(DeviceModel).PivotFields("Count of Device ID"), Value1:=10
End Sub
This part works:
ActiveSheet.PivotTables(DeviceModel).PivotFields("Baseline Release").AutoSort _
xlDescending, "Count of Device ID"
But the second part doesn't:
ActiveSheet.PivotTables(DeviceModel).PivotFields("Baseline Release"). _
PivotFilters.Add Type:=xlValueIsGreaterThan, DataField:=ActiveSheet. _
PivotTables(DeviceModel).PivotFields("Count of Device ID"), Value1:=10
If I replace (DeviceModel) with ("123 Model_name") it works as expected:
ActiveSheet.PivotTables("123 Model_name").PivotFields("Baseline Release"). _
PivotFilters.Add Type:=xlValueIsGreaterThan, DataField:=ActiveSheet. _
PivotTables("123 Model_name").PivotFields("Count of Device ID"), Value1:=10
It says: "application defined or object defined error"
I have done extensive googling and still cant figure out why it doesn't work with the variable instead of the actual table name.
with ActiveSheet.PivotTables(DeviceModel).PivotFields("Baseline Release")have a similar result?Dim DeviceModel As Stringbefore you assign it a value.