ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SelectionChange Event (https://www.excelbanter.com/excel-programming/433726-selectionchange-event.html)

James

SelectionChange Event
 
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


Bob Umlas[_3_]

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

"James" wrote in message
...
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




Rick Rothstein

SelectionChange Event
 
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

--
Rick (MVP - Excel)


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

"James" wrote in message
...
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





Bob Umlas[_3_]

SelectionChange Event
 
Yeah, but that takes 3 keystrokes more and the "$" takes 2!
:-)

"Rick Rothstein" wrote in message
...
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

--
Rick (MVP - Excel)


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

"James" wrote in message
...
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







Rick Rothstein

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

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

<g

--
Rick (MVP - Excel)


"Bob Umlas" wrote in message
...
Yeah, but that takes 3 keystrokes more and the "$" takes 2!
:-)

"Rick Rothstein" wrote in message
...
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

--
Rick (MVP - Excel)


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

"James" wrote in message
...
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








Dave Peterson

SelectionChange Event
 
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



James wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com