Hello,
I have the below code as a worksheet event code in my Worksheet titled "Data". Is there a way to edit this code to filter by two criteria, and not just one? I want to filter column 8 based on the criteria at G2 and H2. Is this possible?
Sorry for the additional edit; but in addition, I have 4 different columns to sort, not just column 8. Can I just use this same code 4 times, one for each column, or is there an easier way/elegant way of doing that?
For example, I want column 5 to be filtered based on cell B1, column 6 to be filtered based on cell C1, column 7 to be filtered based on D1 & E1, and column 8 to be filtered based on F1 & G1. Is this possible?
I have the below code as a worksheet event code in my Worksheet titled "Data". Is there a way to edit this code to filter by two criteria, and not just one? I want to filter column 8 based on the criteria at G2 and H2. Is this possible?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$2" Then
If Range("G2") = "All" Then
Range("A5").AutoFilter
Else
Range("A5").AutoFilter Field:=8, Criteria1:=Range("G2")
End If
End If
End Sub
Sorry for the additional edit; but in addition, I have 4 different columns to sort, not just column 8. Can I just use this same code 4 times, one for each column, or is there an easier way/elegant way of doing that?
For example, I want column 5 to be filtered based on cell B1, column 6 to be filtered based on cell C1, column 7 to be filtered based on D1 & E1, and column 8 to be filtered based on F1 & G1. Is this possible?
Last edited: