+ Reply to Thread
Results 1 to 5 of 5

VB Code causes "undo" to stop functioning

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    4

    VB Code causes "undo" to stop functioning

    I've added the following code to highlight cells when they change
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1:IV65536"
    
     
    
    On Error GoTo ws_exit:
    
    Application.EnableEvents = False
    
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    
    With Target
    
    .Interior.ColorIndex = 3
    
    End With
    
    
    
    
    
    End If
    
    Const WS_RANGE_B As String = "X2:AA5000"
    
     If Not Intersect(Target, Me.Range(WS_RANGE_B)) Is Nothing Then
    
    With Target
    
    .Interior.ColorIndex = 27
    
    End With
    
    
    
    
    
    End If
    
    ws_exit:
    
    Application.EnableEvents = True
    
    End Sub
    All works as I want but the "undo" function in excel is now not working. When I remove the code it works again?
    Any ideas

    Thanks
    Rory
    Last edited by dominicb; 04-07-2010 at 10:52 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: VB Code causes "undo" to stop functioning

    Good afternoon Rory Murphy

    Please note our rule regarding code tags : I have added them for you on this occasion - please be sure to use them in future to avoid your thread being closed. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    It is unfortunate that using macros usually clears the undo stack - most, but not all instructions will cause this to happen. As your macro fires every time a change is made to your worksheet, the undo is constantly being cleared.

    There is no workaround. Choose to live without your macro firing at every change, or choose to live without the undo functionality.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-25-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB Code causes "undo" to stop functioning

    DominicB
    Appreciate the feedback and thanks for the heads up on code tags

    Thanks
    Rory

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: VB Code causes "undo" to stop functioning

    You can't undo changes to a workbook made with VBa, removing the code makes no difference, you can only undo manual changes. Try some manual changes after your code runs you will be able to Undo them.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: VB Code causes "undo" to stop functioning

    Cheers
    Andy
    www.andypope.info

+ 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