Can I Run More Than One Private Sub Worksheet_Change(ByVal Target As Range) Macros?

pwebley

Board Regular
Joined
Mar 2, 2011
Messages
69
I have a spreadsheet with a table of parts in it. Above the table I have 3 data validation boxes that I want to automatically trigger filters on the table. I can get the first one to work fine but the other two I am having troubles with. The first one triggers it's own column filter. The other two work a filter on the same column. How can I get them all to run when the cell value in them is changed?

Here is the code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
 Application.ScreenUpdating = False
ActiveSheet.ListObjects("Table32").Range.AutoFilter Field:=3, Criteria1:= _
        Range("C8").Value, Operator:=xlAnd
 Application.ScreenUpdating = True
  ActiveSheet.Protect , AllowFiltering:=True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
 Application.ScreenUpdating = False
ActiveSheet.ListObjects("Table32").Range.AutoFilter Field:=4, Criteria1:= _
        Range("C12").Value, Operator:=xlAnd
 Application.ScreenUpdating = True
  ActiveSheet.Protect , AllowFiltering:=True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
 Application.ScreenUpdating = False
    ActiveSheet.ListObjects("Table32").Range.AutoFilter Field:=4, Criteria1:= _
        Range("C12").Value, Operator:=xlOr, Criteria2:=Range("C16")
 Application.ScreenUpdating = True
  ActiveSheet.Protect , AllowFiltering:=True
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe loke this

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
 Application.ScreenUpdating = False
ActiveSheet.ListObjects("Table32").Range.AutoFilter Field:=3, Criteria1:= _
        Target.Value, Operator:=xlAnd
 Application.ScreenUpdating = True
  ActiveSheet.Protect , AllowFiltering:=True
End Sub
 
Upvote 0
That works if I want them all to run at the same time but what if I want the filters applied only when each cell is changed individually so as to apply filters at different times and not all at once. The first filter should not be connected with the second. The second should be connected with the third but the third builds off of the second because the apply to the same column using the "or" custom filter.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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