Hi Excel Geniuses,
I have a pivot table that contains some location data called "Milepost". One column is Start Milepost and the other is End Milepost. I need to be able to be able to filter data that is greater than or equal to the Start Milepost AND less than or equal to the End Milepost.
What I need to be able to do is to have the user enter a number on a cell for Start Milepost and another number on another cell for End milepost and use those values to apply the filters to the columns accordingly.
I wrote the VBA code below but it's not working and I'm stuck. HELP!
I have a pivot table that contains some location data called "Milepost". One column is Start Milepost and the other is End Milepost. I need to be able to be able to filter data that is greater than or equal to the Start Milepost AND less than or equal to the End Milepost.
What I need to be able to do is to have the user enter a number on a cell for Start Milepost and another number on another cell for End milepost and use those values to apply the filters to the columns accordingly.
I wrote the VBA code below but it's not working and I'm stuck. HELP!
VBA Code:
Sub PivotFilter()
ActiveSheet.PivotTables("PivotTable2").PivotFields("Start MP").PivotFilters. _
Add2 Type:=xlCaptionIsGreaterThanOrEqualTo, Value1:=Sheets("Consolidated Pivot").Range("A1").Value
ActiveSheet.PivotTables("PivotTable2").PivotFields("End MP").PivotFilters.Add2 _
Type:=xlCaptionIsLessThanOrEqualTo, Value:=Sheets("Consolidated Pivot").Range("B1").Value
End Sub