Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Change event occurs

Excel & Windows XP
The following simple Change event macro fires if the active cell is blank
and I hit the Delete key. Since no change to the contents of the cell
occurred, why does it fire?
Thanks for your help. Otto
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "It changed."
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Change event occurs


Otto Moehrbach wrote:
Excel & Windows XP
The following simple Change event macro fires if the active cell is blank
and I hit the Delete key. Since no change to the contents of the cell
occurred, why does it fire?
Thanks for your help. Otto
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "It changed."
End Sub


Presumably because Change is fired on any assignment - even if the
assignment was not a genuine change. If you have a cell containing say
5 and you enter 5 in that cell, it would also fire. There would be a
definite overhead in comparing the old value and the new value of a
range before firing the event. In the off-hand chance you want the
event to fire only in the event of an actual change you could mimic
this in code by storing the old data (maybe by having the selection
change event write it to a public variable) and then compare it at the
start of the change event, terminating the call if the values are the
same.

Hope that helps

-John Coleman

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Change event occurs

Thanks John. Otto
"John Coleman" wrote in message
oups.com...

Otto Moehrbach wrote:
Excel & Windows XP
The following simple Change event macro fires if the active cell is blank
and I hit the Delete key. Since no change to the contents of the cell
occurred, why does it fire?
Thanks for your help. Otto
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "It changed."
End Sub


Presumably because Change is fired on any assignment - even if the
assignment was not a genuine change. If you have a cell containing say
5 and you enter 5 in that cell, it would also fire. There would be a
definite overhead in comparing the old value and the new value of a
range before firing the event. In the off-hand chance you want the
event to fire only in the event of an actual change you could mimic
this in code by storing the old data (maybe by having the selection
change event write it to a public variable) and then compare it at the
start of the change event, terminating the call if the values are the
same.

Hope that helps

-John Coleman



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
Need to determine where a change in table occurs Wox Excel Discussion (Misc queries) 6 July 28th 09 02:48 AM
execute code in one worksheet when change occurs in another suzetter Excel Programming 6 June 16th 05 06:37 PM
conditional cell shading when a change occurs zooeyhall Excel Discussion (Misc queries) 1 June 6th 05 05:14 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
event which occurs when a TextBox receives focus Mikhail Excel Programming 2 October 7th 03 02:27 PM


All times are GMT +1. The time now is 07:52 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"