+ Reply to Thread
Results 1 to 4 of 4

Excel 2007 : Worksheet_Change

  1. #1
    Registered User
    Join Date
    12-05-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2007
    Posts
    40

    Question Worksheet_Change

    Hello folks,

    In the code shown below I am trying to error check the date the user has entered against the list of imported dates, which works fine except when the last line is executed in the "Else" block - which is supposed to replace the incorrect entered date with the original default value.

    It seems that re-assignment triggers the "Worksheet_Change" event again (?) and because the date is now "in range" again, the "Then" block gets executed!?!

    Is that what is happening? Why else would I see the MsgBox "Date Entered in in Range." every time, after seeing the MsgBox "Error! X_axis..."?

    Please Login or Register  to view this content.
    So, here is an attempt to "out-wit" the VB logic, by having that Error flag set to 1 at the time of the re-assigment, but it doesn't work. I still see the logic passing through the "Then" block after the re-assignment in the "Else" block.

    Please Login or Register  to view this content.
    Any ideas how I can put a correct data value back in the cell after the user enters an invalid date? Without triggering the "Worksheet_Change" event? Help!

    - Thomas
    Last edited by ThomasHaller; 12-19-2011 at 11:58 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Please help me solve this Sub Worksheet_Change "Catch-22"

    See if this works
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-05-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Please help me solve this Sub Worksheet_Change "Catch-22"

    Hello royUK,

    I will try that, what I found myself was that second block of code works, if I declare the "Dim Error as Integer" outside of the If statement, as a "Static" variable. So here is the block that works fairly well:

    Please Login or Register  to view this content.
    But I will play with your suggestion, just to see how it works.

    - Thomas

  4. #4
    Registered User
    Join Date
    12-05-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2007
    Posts
    40

    Re: Please help me solve this Sub Worksheet_Change "Catch-22"

    Hello again royUK,

    Your solution works nicely and I like it much better than my messy "Error" flag!

    SOLVED!

    - Thomas

+ 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