Call Macro when click a range of cells

kabootar

New Member
Joined
Jan 15, 2019
Messages
10
Hi Guys,

I have the below code where I want a macro to run when a range of cells is selected(clicked).

The code is:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next
If Not Intersect(Target, Sheet3.Range("Q1_COL")) Is Nothing Then

Sheet6.Range("D4").Value = Target.Value

ElseIf Not Intersect(Target, Sheet3.Range("Q2_COL")) Is Nothing Then

Sheet3.Range("N2").Value = Target.Value
If Sheet3.Range("N2").Value > 0 Then
Call MyMacro
End If

End If

End Sub


The second part is where I need the macro to run.
Just an FYI, there are two table on the sheet, hence the reason for two ranges.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I have tested your procedure (below) and added MyMacro and "Hello" appears when the value selected in range Q2_COL is greater than 0 - so it works

But you are unhappy with it..
- so what happens that you do NOT want ? or what does NOT happen that you do want ?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Not Intersect(Target, Sheet3.Range("Q1_COL")) Is Nothing Then
        Sheet6.Range("D4").Value = Target.Value
    ElseIf Not Intersect(Target, Sheet3.Range("Q2_COL")) Is Nothing Then
        Sheet3.Range("N2").Value = Target.Value
        If Sheet3.Range("N2").Value > 0 Then
            Call MyMacro
        End If
    End If
End Sub

Sub MyMacro()
    MsgBox "hello"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,968
Messages
6,175,677
Members
452,666
Latest member
AllexDee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top