Skip to main content
Support is Online
We're back! We are here to assist you. Please be patient, we will respond to your tickets shortly.
Official support hours
Monday To Friday
From 09:00 To 17:30
  Anonymous User
  Monday, 06 February 2023
  0 Replies
  1.6K Visits
0
Votes
Undo
Good day

I've come across VBA code that works really well to trigger a macro in Excel when clicking on a specific cell. See below:


Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D4")) Is Nothing Then
Call MyMacro
End If
End If
End Sub


I'm trying to add 3 more such scenarios to the same code, but I have no experience with coding, so troubleshooting has gotten me nowhere. Please see below example of what I'm trying to do, and correct the code if possible:


Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D4")) Is Nothing Then
Call MyMacro1
End If
End If
If Selection.Count = 1 Then
If Not Intersect(Target, Range("E10")) Is Nothing Then
Call MyMacro2
End If
End If
If Selection.Count = 1 Then
If Not Intersect(Target, Range("G23")) Is Nothing Then
Call MyMacro3
End If
End If
If Selection.Count = 1 Then
If Not Intersect(Target, Range("J33")) Is Nothing Then
Call MyMacro4
End If
End If
End Sub



I was expecting the various macros I created (that work well) to automatically run when the cells noted in the code were clicked on


Any assistance will be greatly appreciated!
There are no replies made for this post yet.