multiple unique worksheet change events

dgrimm

Board Regular
Joined
Sep 17, 2007
Messages
159
I am trying to create a worksheet change event for multiple worksheet changes to update pivot tables. First off I am getting an error end if without if for the first one. And I know it won't reach the second because it will exit the sub if the first one is not met.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String

On Error Resume Next

If Intersect(Target, Sheets("Selection").Range("B17")) Is Nothing Then Exit Sub
xStr = Worksheets("Selection").Range("B17")
Application.ScreenUpdating = False
Worksheets("Pivot 2").Activate
ActiveSheet.PivotTables("BranchJob").PivotFields("Division").ClearAllFilters
ActiveSheet.PivotTables("BranchJob").PivotFields("Division").CurrentPage = xStr
ActiveSheet.PivotTables("BranchJob").RefreshTable
End If

If Intersect(Target, Sheets("Selection").Range("B18")) Is Nothing Then Exit Sub
xStr = Worksheets("Selection").Range("B18")
Application.ScreenUpdating = False
Worksheets("Pivot 2").Activate
ActiveSheet.PivotTables("BranchJob1").PivotFields("Branch Description").ClearAllFilters
ActiveSheet.PivotTables("BranchJob1").PivotFields("Branch Description").CurrentPage = xStr
ActiveSheet.PivotTables("BranchJob1").RefreshTable
End If

Application.ScreenUpdating = True
End Sub

Once I can get these two straight I can add the others.

Thank you
Dave
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You don't use End If when your If statement is a single line. Try removing both the "End If"s
 
Upvote 0
Try it like
VBA Code:
If Not Intersect(Target, Range("B17")) Is Nothing Then
   xStr = Worksheets("Selection").Range("B17")
   Application.ScreenUpdating = False
   Worksheets("Pivot 2").Activate
   ActiveSheet.PivotTables("BranchJob").PivotFields("Division").ClearAllFilters
   ActiveSheet.PivotTables("BranchJob").PivotFields("Division").CurrentPage = xStr
   ActiveSheet.PivotTables("BranchJob").RefreshTable
End If
 
Upvote 0
Try it like
VBA Code:
If Not Intersect(Target, Range("B17")) Is Nothing Then
   xStr = Worksheets("Selection").Range("B17")
   Application.ScreenUpdating = False
   Worksheets("Pivot 2").Activate
   ActiveSheet.PivotTables("BranchJob").PivotFields("Division").ClearAllFilters
   ActiveSheet.PivotTables("BranchJob").PivotFields("Division").CurrentPage = xStr
   ActiveSheet.PivotTables("BranchJob").RefreshTable
End If
Many thxz Fluff that did the trick....
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top