+ Reply to Thread
Results 1 to 8 of 8

loop to stop and wait for cell value change.

  1. #1
    Registered User
    Join Date
    09-25-2007
    Posts
    13

    loop to stop and wait for cell value change.

    I'm very new to this, but I have a simple macro that is working largely as intended. I want it to look at a cell, and give the user an error message if the cell value is less than or equal to a referenced cell. I want it to keep checking the cell, but I need to give the user an opportunity to change the value before each check. Can I set up some trigger that activates when the user enters data into the cell?

    This is my code:

    Please Login or Register  to view this content.
    I appreciate any help.

  2. #2
    Registered User
    Join Date
    09-25-2007
    Posts
    13
    Well, I've partially found my solution. I modified the code as follows:

    Please Login or Register  to view this content.
    This works great as long as I keep entering values into cellB2 that cause the message box to appear. Once I enter a value that is greater than the value in cell A2, then spreadsheet accepts the value, then after a few seconds, Excel freezes.

    Any ideas why?

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    HI

    Try

    Please Login or Register  to view this content.

    rylo

  4. #4
    Registered User
    Join Date
    09-25-2007
    Posts
    13
    Sorry for the late reply. I tried your suggestion, and it didn't work. I thought that it might be because I have Excel set to automatically move the selection after pressing enter. When I disabled that option, it works fine.

    The reason I initially have the line in there to select range B2 was to make sure it was looking at the correct cell, even if the selected cell is not B2. I replaced that line, and now it works great. My final macro code is:

    Please Login or Register  to view this content.
    Thanks for your help!
    Last edited by ajwhipple; 10-02-2007 at 06:59 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Perhaps this:
    Please Login or Register  to view this content.
    Note that this goes in the Worksheet module, not the Workbook module.

    If you want B2 fixed before the user is allowed to change anything else, then,
    Please Login or Register  to view this content.
    Also be aware that when the change event changes the worksheet (like clearing the contents of B2), Excel flushes the Undo buffer, which may aggravate users.
    Last edited by shg; 10-02-2007 at 07:12 PM.

  6. #6
    Registered User
    Join Date
    09-25-2007
    Posts
    13
    I do want the users to correct the value before they move on, so I tried your second code set. Unfortunately, it wouldn't allow me to enter a new value after it cleared the cell, because the cell was empty, which triggered the message box. I changed the code as follows:

    Please Login or Register  to view this content.
    Now it ends the macro if the cell is empty too. Unfortunately, it also allows the user to leave the cell blank, which isn't exactly desireable either. There are further operations in the sheet that will require values for both cells, so the omission would be caught later, but it would be nice to catch it in the beginning too.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Another approach would be to wait until the user enters another control value via an input box. (I may have mixed up your high/low cells)
    Please Login or Register  to view this content.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    ... it wouldn't allow me to enter a new value after it cleared the cell, because the cell was empty
    Sorry, the Undo should appear after events are disabled.

    Mike's solution looks good also.

+ 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