+ Reply to Thread
Results 1 to 4 of 4

macro clears undo stack - can I stop it doing that?

  1. #1
    Registered User
    Join Date
    02-25-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    62

    macro clears undo stack - can I stop it doing that?

    Hi there
    I have VBA in the worksheet in the attached workbook which is designed to copy down formulas (columns e:f and m:al) down to rows which contain text in any of columns g:j.

    So if, for example, if I go into cell g6 and input something and press enter, formulas are copied down from row 5 into row 6. If I then go into cell g6 and press delete, then the formulas are cleared from row 6.

    But when I make aforementioned changes in the worksheet, I can't undo them by pressing the undo button or ctrl+z.

    So, in the attached workbook, if I go into cell g6 and press delete, the text in cell g6 is lost forever.

    Is there a way to stop the macro from clearing the undo stack?

    Thanks, Stu

    Please Login or Register  to view this content.

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

    Re: macro clears undo stack - can I stop it doing that?

    To my knowledge, there is no way to prevent VBA from clearing the undo stack. You can write your own undo procedure that can undo the changes your procedure made (usually requiring your procedure to store everything somewhere before it makes changes) using the application.onundo method https://docs.microsoft.com/en-us/off...ication.OnUndo
    This thread links to a tutorial using class modules to create a more generic undo handler https://www.excelforum.com/excel-pro...tion-back.html but I believe it still cannot prevent VBA from clearing the undo stack. It only allows you to undo changes made by the most recently run procedure.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: macro clears undo stack - can I stop it doing that?

    To be clear on this point, unlike the Excel application VBA does not implement an UnDo function. Excel can do this because a temporary copy of the workbook is open until the main workbook is closed. The temporary file is where changes are made to.

    In VBA, you can only undo the last change you made in a procedure using Application.Undo. The reason is there is no running list of user changes like in Excel.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    02-25-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    62

    Re: macro clears undo stack - can I stop it doing that?

    Okay thank you both very much for explaining that.

+ 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. macro paste values and keep Undo stack
    By HengeN in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2017, 04:32 AM
  2. Replies: 0
    Last Post: 11-22-2014, 05:02 PM
  3. Re-running macro clears row 1 - why?
    By SDBoca in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2011, 02:58 PM
  4. Stop undo stack from clearing
    By ohiggs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2009, 05:32 PM
  5. Running macros/events clears undo history and clipboard
    By Creisti86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2007, 10:33 AM
  6. Excel undo stack
    By NSK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2007, 06:40 AM
  7. vba undo stack
    By anandb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2005, 02:06 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