I need help cleaning this up. I'm fairly new to the process (only dabbled in it for a couple of years) and most of it seems bulky. Any help is appreciated.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("D1")) Is Nothing Then Exit Sub
On Error GoTo Error_handler
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets("Pivot").PivotTables("DrillingInt")
Set Field = pt.PivotFields("AFE")
NewCat = Worksheets("Well Detail").Range("D20").Value
NewCat2 = Worksheets("Well Detail").Range("A1").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
Set pt = Worksheets("Pivot").PivotTables("CompInt")
Set Field = pt.PivotFields("AFE")
NewCat = Worksheets("Well Detail").Range("D112").Value
NewCat2 = Worksheets("Well Detail").Range("A1").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
Set pt = Worksheets("Pivot").PivotTables("EquipInt")
Set Field = pt.PivotFields("AFE")
NewCat = Worksheets("Well Detail").Range("D204").Value
NewCat2 = Worksheets("Well Detail").Range("A1").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
Worksheets("Pivot").PivotTables("DrillingInt").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("DrillingInt").PivotFields("Account Number"). _
PivotFilters.Add2 Type:=xlCaptionIsNotBetween, Value1:="71000", Value2:= _
"72000"
Worksheets("Pivot").PivotTables("DrillingTan").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("DrillingTan").PivotFields("Account Number"). _
PivotFilters.Add2 Type:=xlCaptionIsBetween, Value1:="71000", Value2:= _
"72000"
Worksheets("Pivot").PivotTables("CompInt").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("CompInt").PivotFields("Account Number").PivotFilters. _
Add2 Type:=xlCaptionIsNotBetween, Value1:="71000", Value2:="72000"
Worksheets("Pivot").PivotTables("CompTan").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("CompTan").PivotFields("Account Number").PivotFilters. _
Add2 Type:=xlCaptionIsBetween, Value1:="71000", Value2:="72000"
Worksheets("Pivot").PivotTables("EquipInt").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("EquipInt").PivotFields("Account Number").PivotFilters. _
Add2 Type:=xlCaptionIsNotBetween, Value1:="71000", Value2:="72000"
Worksheets("Pivot").PivotTables("EquipTan").PivotFields("Account Number"). _
ClearLabelFilters
Worksheets("Pivot").PivotTables("EquipTan").PivotFields("Account Number").PivotFilters. _
Add2 Type:=xlCaptionIsBetween, Value1:="71000", Value2:="72000"
Exit Sub
Error_handler:
Field.ClearAllFilters
Field.CurrentPage = NewCat2
pt.RefreshTable
If Result = vbOK Then Resume Next
End Sub