SelectionChange Event

J

James

I am trying to use the worksheet_selectionchange event and it doesn't seem to
be doing anything. I would like to call a sub routine when the user clicks on
cell "a18"

I am trying just to see if I can get the event to trigger and no matter what
I do nothing happens

right now I tried this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "A18" Then
MsgBox "hello"
End If

End Sub

This is in the worksheet that I want it to run for

Do I have to turn on anything for this event to work?
Am I missing something?

Thanks
 
B

Bob Umlas

The Target.Address has the "$" in it. Change your code to:
If target.Address = "$A$18" Then...
 
R

Rick Rothstein

To follow up...

Or, if you want to use addresses without the $ signs, then do it this way...

If Target.Address(0, 0) = "A18" Then
 
R

Rick Rothstein

Then I'm glad I didn't suggest using this...

If Target.Address = Range("A18").Address Then

<g>
 
D

Dave Peterson

Another ...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

if target.cells.count > 1 then
exit sub 'single cell at a time
end if

if intersect(target, me.range("A18")) is nothing then
exit sub
end if

msgbox "hi"

End sub

I find that this syntax is easier to modify if I have to monitor other ranges:

if intersect(target, me.range("A18:B22,D:E,G18,L98")) is nothing then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top