jeudi 6 avril 2017

Nesting two IF statements inside a selection change, both with exit sub and call module

I want to combine these 2 codes into 1:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Intersect(Target, Range("AL1")) Is Nothing Then Exit Sub
  Application.Run "Module2.Sub1"
end sub

and

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Intersect(Target, Range("AL2")) Is Nothing Then Exit Sub
      Application.Run "Module2.Sub2"
end sub

Doing like this cancels out the second IF statement, but keeps working for the first one

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("AL1")) Is Nothing Then Exit Sub
      Application.Run "Module2.Sub1"
If Intersect(Target, Range("AL2")) Is Nothing Then Exit Sub
      Application.Run "Module2.Sub2"
end sub

I found the copde snippet online, I guess I don't need an End If because of the exit sub...But I really need help to get my head around this one. Help?

I'm doing this to be able to have tool tips for the shapes that run my macros.

Aucun commentaire:

Enregistrer un commentaire