Application.Undo not working (EnableEvents = false)

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I found the following code to report cell changes:

Workbook event:
Rich (BB code):
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
            
   If Target.Parent.Name <> wSummary.Name Then Exit Sub
     
   Application.EnableEvents = False
   LogChange Target
   Application.EnableEvents = True
                    
End Sub
And procedure:
Rich (BB code):
Public Sub LogChange(ByRef rTarget As Range)
     
    Dim vNewValues  As Variant
    Dim vRecords    As Variant
    Dim msg(1 To 3) As String
    Dim rng     As Range
     
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    On Error GoTo ExitProc
    
    With rTarget
        If .CountLarge = 1 Then
            Set rng = Selection
            msg(2) = .Value
            On Error Resume Next: Application.Undo: On Error GoTo ExitProc
            msg(1) = .Value
            .Value = msg(2)
            rng.Select
        Else
          On Error Resume Next
          msg(3) = Application.CommandBars("Standard").FindControl(ID:=128).List(1)
          On Error GoTo ExitProc
        
          msg(1) = "Operation: " & msg(3)
          msg(2) = "Changed: " & .CountLarge & " cells."
        End If
                            
        vRecords = Log_Sheet_Headers(rTarget, msg)
        With wLog.Cells(Rows.Count, 1).End(xlUp)(2).Resize(1, UBound(vRecords) - LBound(vRecords) + 1)
            .Value = vRecords
            .EntireColumn.AutoFit
        End With
    End With
    
    Erase vNewValues: Erase vRecords: Set rng = Nothing
    
ExitProc:
    With Application
       .ScreenUpdating = True
       .Calculation = xlCalculationAutomatic
    End With
     
End Sub
This was working on Friday, when it would undo the action but not today and I've made no code changes, but the output shows the old value and new value as the new value - due to the .undo not working as far as I can tell.

Any ideas/suggestions?

TIA,
Jack
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top