PDA

View Full Version : Conditionally Manage Multiple Items In Worksheet_Change(ByVal Target As Range) Event



Rajesh Kr Joshi
07-22-2014, 02:29 PM
Hi,
I am using the below code to change the filter in range "B11:K11" based on a dropdown in cell C1 and it is working fine. I want to add another event in the same code targeting range "G12:G31" and "I12:I31" triggering MsgBox "Test".


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$C$1" Then

If Range("C1") = "All" Then
ActiveSheet.AutoFilterMode = False
Else
ActiveSheet.AutoFilterMode = False
ActiveSheet.Range("B11:K11").Select
Selection.AutoFilter 1, ActiveSheet.Range("C1").Value


End If
End If

End Sub

Thanks
Raj

Admin
07-23-2014, 07:31 AM
Hi

try something like


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$C$1" Then
If Range("C1") = "All" Then
ActiveSheet.AutoFilterMode = False
Else
ActiveSheet.AutoFilterMode = False
ActiveSheet.Range("B11:K11").Select
Selection.AutoFilter 1, ActiveSheet.Range("C1").Value
End If

ElseIf Not Application.Intersect(Target, Range("G12:G31")) Is Nothing Then
'your action here
ElseIf Not Application.Intersect(Target, Range("I12:I31")) Is Nothing Then
'your action here
End If

End Sub

Rajesh Kr Joshi
07-23-2014, 12:12 PM
Awesome, working great:)

Thanks again
Raj