I don't have a lot of experience with VBA and there's one error that keeps bugging me. The following code does exactly what I want, with the exception that I get the "Method Intersect of Object _Global Failed" error every time I update cell B3. What am I doing wrong? I thought I was being specific on the worksheet to avoid this issue. I've tried changing the Worksheets from (1) to the actual name of the sheet ("Principal") with no luck.
The bold section is what's being highlighted in yellow when I try to debug.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Worksheets(1).Range("B3:B4")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets(1).PivotTables("PivotTable4")
Set Field = pt.PivotFields("Paciente")
NewCat = Worksheets(1).Range("B3").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub
The bold section is what's being highlighted in yellow when I try to debug.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Worksheets(1).Range("B3:B4")) Is Nothing Then Exit Sub
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
Set pt = Worksheets(1).PivotTables("PivotTable4")
Set Field = pt.PivotFields("Paciente")
NewCat = Worksheets(1).Range("B3").Value
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub