Vba experts: Executing a macro when certain cells are selected

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
834
Office Version
  1. 365
Platform
  1. Windows
Is there away to execute a macro after selecting a few certain cells???
 
I keep getting a compile error:Ambiguous name detected:Worksheet_SelectionChange

I have a Selection Change in the sheet code already, that may be messing it up.
Here is everything in the Sheet Code

Then one you made is at the bottom. Thanks

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$G$1:$J$1" Then
Call FINALIZED_BY_QC_job
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$A$4,$J$10" Then
Call SHOW_LIST
End If
End Sub
 
Upvote 0
You can only have one procedure for each event. Try:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) 
    If Target.Address = "$G$1:$J$1" Then
        Call FINALIZED_BY_QC_job
    ElseIf Target.Address = "$A$4,$J$10" Then
        Call SHOW_LIST
    End If
End Sub
 
Upvote 0
Andrew, as soon as I select any cell this error comes up Compile error: Expected variable or procedure,not module. And it highlights the Call SHOW_LIST

Im not sure what this means, SHOW LIST is a macro.
 
Upvote 0
Make sure that the procedure SHOW_LIST isn't in a module with the same name. Change the name of the module if necessary.
 
Upvote 0
ok makes since. I noticed that I have to hold down the CTRL button while selecting the cells, Is this correct?
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,045
Members
453,772
Latest member
aastupin

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