I am a self taught VBA user but have done pretty well by combining code "writing" with code "recording" to maximize my abilities in Excel. Here is my issue. I have a file that I built for someone who has Excel 2010 (I have 2016). I 'recorded' a simple macro to set a value filter in a pivot table to be "less than or equal to zero". It works fine for me when I execute the macro, but when the user tries to execute within Excel 2010, she gets an error. It is getting hung up when trying to apply the value filter, and I'm wondering if there is something with the syntax when recording this macro in 2016 that isn't downwardly compatible with 2010. Is there an cleaner/simpler way for me to express what I'm trying to do (set the value filter) that would be compatible with both versions?
Code:
Sub Filter_Margin_Analysis()
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'Filter items where Units <> 0, and Margin % < Target
If Range("L17").Value = "Filtered" Then
ActiveSheet.PivotTables("Margin_Analysis").PivotFields("product_code"). _
ClearValueFilters
ActiveSheet.PivotTables("Margin_Analysis").PivotFields("product_code"). _
PivotFilters.Add2 Type:=xlValueIsLessThan, DataField:=ActiveSheet. _
PivotTables("Margin_Analysis").PivotFields(" +/- Target"), Value1:=0, Order _
:=0
Else
ActiveSheet.PivotTables("Margin_Analysis").PivotFields("product_code"). _
PivotFilters.Add2 Type:=xlValueIsLessThan, DataField:=ActiveSheet. _
PivotTables("Margin_Analysis").PivotFields(" +/- Target"), Value1:=0, Order _
:=0
Range("L17").Value = "Filtered"
End If
End Sub
Last edited by a moderator: