+ Reply to Thread
Results 1 to 3 of 3

Change event occurs

  1. #1
    Otto Moehrbach
    Guest

    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. #2
    John Coleman
    Guest

    Re: 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. #3
    Otto Moehrbach
    Guest

    Re: Change event occurs

    Thanks John. Otto
    "John Coleman" <jcoleman@franciscan.edu> wrote in message
    news:1133532932.132213.268450@g49g2000cwa.googlegroups.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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1