+ Reply to Thread
Results 1 to 3 of 3

Undoing a "click" on a cell inside VBA

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    Nashville, TN
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Undoing a "click" on a cell inside VBA

    Hi,

    I just implemented a nice Event Handler with forum's help (TMS, thank you!) where I sense cell clicks and update a counter. However, being a stickler for UI experience I always need to "Undo" any previous action to help with any unintended clicks. Well, it looks like this undoing may not be possible (or easy) as with the regular Excel Undo button on the top left corner! My immediate searches tell me that I have to write another macro to undo any event handling macro did. Do you guys know of any simple Undo trick while you are inside of a VBA macro? I.E., just forget the previously recognized "click" in some cell?

    Thanks much in advance.

    Best, Nash

  2. #2
    Valued Forum Contributor PeteABC123's Avatar
    Join Date
    09-21-2012
    Location
    Chicago, IL
    MS-Off Ver
    MS Office 365 ver 2202
    Posts
    1,104

    Re: Undoing a "click" on a cell inside VBA

    Best practice is to envision possibly going back after the macro runs. If you think you might need to go back, SAVE your file first. Run the macro, and exit w/o saving if it didn't go well..
    Running a Macro deletes your UNDO list.

    (Edit: did stumble into this though. . .I can't vouch for it.) https://jkp-ads.com/Articles/UndoWithVBA00.asp


    Pete
    Last edited by PeteABC123; 02-02-2021 at 01:18 PM.

  3. #3
    Registered User
    Join Date
    12-21-2011
    Location
    Nashville, TN
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Re: Undoing a "click" on a cell inside VBA

    Quote Originally Posted by PeteABC123 View Post
    Best practice is to envision possibly going back after the macro runs. If you think you might need to go back, SAVE your file first. Run the macro, and exit w/o saving if it didn't go well..
    Running a Macro deletes your UNDO list.

    (Edit: did stumble into this though. . .I can't vouch for it.) https://jkp-ads.com/Articles/UndoWithVBA00.asp


    Pete
    I've implemented a sort of "Undo" button but I can't seem to undo everything that happened on the click! In the attached code I can highlight the cell clicked and then un-highlight it with a double click.

    However, when I click and highlight I also transfer the contents of the clicked cell into an accumulator. So if I double-click the same cell I should un-highlight AND also reduce the accumulator value by the same amount that was added upon clicking the first time .. right? This is where I see the problem -

    It works well the first few times - i.e., click => highlight and add to accumulator; double-click => un-highlight and subtract from accumulator. After a few clicks, the accumulator contents stays the same and won't change!

    Is the problem too many clicks and double-clicks? Why does the part of accumulator changes fail after a while?

    Can somebody test my code and let me know where the bug is?
    Thanks much in advance.

    Best, Nash
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 9
    Last Post: 09-25-2013, 06:26 PM
  2. Toggle BackColor of labels in Userform through "click" and "double-click"
    By ahmerjaved in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2013, 02:08 PM
  3. If I click the Vendor 1 column of cell "J13" that value goes to place in worksheet of "Ve
    By suresh mongam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2012, 02:41 PM
  4. Difference between manual "click" of activeX checkbox and coded "click"
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-23-2012, 10:51 AM
  5. [SOLVED] Disable "Right Click" ... or any ability to "cut", "insert", etc.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2011, 09:26 AM
  6. Overwriting a cell, copying the new value, and then "undoing" back to original val.
    By chuggins143 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2010, 05:56 PM
  7. Replies: 8
    Last Post: 01-04-2006, 12:10 PM

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