Excel VBA Run Macro on Cell Selection

  • I know I have read similar posts on this but I don't know enough to be able to modify what I've found into what I need.


    I know the below code will run a macro if a specific cell is clicked.


    Code
    Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) 
        If Target.Address = "$A$1" Then
            Call MyMacro 
       End If
    End Sub


    However, I have quite a few cells that if they are clicked I want it to run the same macro and I don't want to have to type thousands of If statements. I know someone smarter than me knows how to do this. :)


    Thank you in advance!
    Jess

  • Re: Excel VBA Run Macro on Cell Selection


    I don't have a continuous range so I tried the below:


    Code
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
        
    If Not Intersect(Range("H54:O79"), Target) Is Nothing Or Intersect(Range("U12:IR78"), Target) Is Nothing Then
        Call Filter_Data
    End If
        
    End Sub


    But when I click on a cell in that range it still doesn't do anything.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!