+ Reply to Thread
Results 1 to 6 of 6

VBA Code to get UNDO function back

  1. #1
    Registered User
    Join Date
    05-04-2018
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    65

    VBA Code to get UNDO function back

    Hi Everyone,

    I have a code running in my worksheet and I am not able to use undo function when the code is running. Undo button does not work on rows that are not even part of the code. I heard of adding Application.Undo in the VBA code but I am not sure how will that work as i tried adding it and VBA doesnt work then. Below is the VBA code that I am using. Can anyone help to get me Undo function back atleast on rows that are not part of the VBA.

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 05-17-2018 at 09:39 PM. Reason: Please use code tags!

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: VBA Code to get UNDO function back

    When a VBA Sub or event procedure is run, it clears the undo stack. To my knowledge, there is no way to preserve the undo stack. Use of the Application.OnUndo method allows you to specify a separate VBA procedure that will execute if/when you execute the undo command -- effectively starting a new undo stack.

    It is one of those programming decisions. If undo is important to the way you use this spreadsheet, then you should probably find a non-VBA, non event procedure way to accomplish the task. If a VBA event procedure is the only way to accomplish what you want, then you are effectively giving up on reliably using undo -- especially with a selection change event, since the selection will change very frequently.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    05-04-2018
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    65

    Re: VBA Code to get UNDO function back

    This VBA is to run the drop down list down to the end of the rows in the sheet. And Undo works on the drop down list which is being run by this VBA. On the cells which are free text and are not controlled by VBA why are those not being able to do get UNDO. Is this how VBA works. I am new to this.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: VBA Code to get UNDO function back

    I am having a hard time visualizing what is going on in your spreadsheet. It might be best if you upload a small sample file that illustrates what you are doing, so we can look at it and offer some alternatives that will keep the undo stack intact.

  5. #5
    Registered User
    Join Date
    05-04-2018
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    65

    Re: VBA Code to get UNDO function back

    I just have this below small VBA. This is helping me to run Dependent Data Validation Lists in 2 columns across one of the sheet in workbook. But the problem is, the rows which are free text or not having data validation lists cannot also have the undo function. Since I am new to VBA, I assume the VBA code should just be restricted to 2 columns in the sheet which have the data validation and should not interfere how rest of the columns in the sheet are dealt with. If my understanding is correct then I should be able to have undo function in every other column.
    Is there way I can achieve this by restriction the VBA to just 2 columns in the sheet and not affecting other columns.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: VBA Code to get UNDO function back

    Nope. Undo cache is cleared when VBA code runs. It's just the way it is.

    In order to get around that, you'd need custom class module to trap previous state.

    Have read of below.
    http://www.jkp-ads.com/Articles/UndoWithVBA00.asp
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

+ 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: 08-07-2016, 09:45 PM
  2. Undo Only Going Back About 9 or 10 Steps
    By lotusman in forum Excel General
    Replies: 2
    Last Post: 06-04-2016, 03:15 PM
  3. [SOLVED] VBA code disables "UNDO" function on spreadsheet
    By toolman_dustin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2015, 12:17 PM
  4. [SOLVED] How to refer to back-to-back rows in code
    By JaydenK in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2013, 03:58 PM
  5. Need some help geting VBA code to work back to back.
    By BrettRCourtney in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-14-2013, 11:00 AM
  6. Undo or Back function
    By leroyb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-01-2012, 02:59 PM
  7. Undo function to undo Visual Basic commands
    By pierre08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2010, 04:59 AM

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