Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default SelectionChange - What am I doing wrong?

Please help. My code is working almost exactly as I want it to, with one exception.

Scenario:

Two Columns A and B
The user makes a change in Column A (example: User changes value of Cell A9 to 5). If the value of the adjacent cell (B5) is greater than the current cell, a msg box appears. Easy, simple, right?

The problem:

My code, thanks to Rob van Gelder and Tom Ogilvy, is working fine. But here is the problem. When the user changes the value of A9, nothing happens. The user will usually enter a new value into the cell and then hit Enter or move to the cell to the right.
If the user hits Enter, we move to the cell below, and my code is not generating a message, as we are now on a different cell (the comparison of the two cells fails).
If the user moves to the right, then he is in column B, and my code is only checking for new entries in Column A.
How can I fix this? Should I not be using the
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
as my main method of looking for a change?

Or should I simply check both columns A and Columns B? What I need is something that does a check as soon as the user moves to a different cell. Thanks. This is giving me a headache.

Doug
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SelectionChange - What am I doing wrong?

Target indicates the cell that triggered the event - a you should be using
the change event, not the selectionchange

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

if Target.Count 1 then exit sub
if Target.Column = 1 then
if Target.Value < Target.offset(0,1).Value then
msgbox "Some Message"
end if
end if
End sub

--
Regards,
Tom Ogilvy


Doug wrote in message
...
Please help. My code is working almost exactly as I want it to, with one

exception.

Scenario:

Two Columns A and B
The user makes a change in Column A (example: User changes value of Cell

A9 to 5). If the value of the adjacent cell (B5) is greater than the current
cell, a msg box appears. Easy, simple, right?

The problem:

My code, thanks to Rob van Gelder and Tom Ogilvy, is working fine. But

here is the problem. When the user changes the value of A9, nothing happens.
The user will usually enter a new value into the cell and then hit Enter or
move to the cell to the right.
If the user hits Enter, we move to the cell below, and my code is not

generating a message, as we are now on a different cell (the comparison of
the two cells fails).
If the user moves to the right, then he is in column B, and my code is

only checking for new entries in Column A.
How can I fix this? Should I not be using the
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
as my main method of looking for a change?

Or should I simply check both columns A and Columns B? What I need is

something that does a check as soon as the user moves to a different cell.
Thanks. This is giving me a headache.

Doug



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SelectionChange - What am I doing wrong?

The only thing I can think of is the default settings. Perhaps in tools,
options, edit, the user needs to change the move after enter selection


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SelectionChange - What am I doing wrong?

No need.

the Change event, using Target, will work fine.

--
Regards,
Tom Ogilvy

Annelie wrote in message
...
The only thing I can think of is the default settings. Perhaps in tools,
options, edit, the user needs to change the move after enter selection


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default SelectionChange - What am I doing wrong?

Tom,

Thank you again. You are a lifesaver of the first degree. I wish you a safe and prosperous 2004.

Doug
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use selectionchange instead of doubleclick event? ghost Excel Discussion (Misc queries) 0 December 24th 08 05:00 AM
Worksheet SelectionChange Event mjack003 Excel Discussion (Misc queries) 2 May 8th 06 08:35 PM
Disable SelectionChange Event BillCPA Excel Discussion (Misc queries) 2 February 17th 06 06:45 PM
Excel Automation SelectionChange event cpotts Excel Discussion (Misc queries) 1 December 20th 04 05:15 PM
SelectionChange code always available René Excel Programming 0 July 13th 03 01:46 PM


All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"