Altering code from Worksheet_Change so that Undo works

michaeltsmith93

Board Regular
Joined
Sep 29, 2016
Messages
83
Hi,

I posted a question about this earlier, but have discovered a little bit more on my own and have run into a different problem. With the following code, the Undo function is effectively removed. Do I have any options for replicating this code but not making it a worksheet change dependent thing and thereby ruining Undo?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim intersection As Range
    Set intersection = Application.Intersect(Target, Me.Range("A:K"))
    If Not intersection Is Nothing Then
        Dim r As Range
        For Each r In intersection.Rows
            r.EntireRow.Range("M1").Value = Date
            r.EntireRow.Range("L1").Value = Application.Username
        Next
    End If
    Application.EnableEvents = True
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You loose the undo stack when any macro makes a change to the sheet, not just change events
 
Last edited:
Upvote 0
If you are editing one cell at a time in column AK then you could probably use sendKeys to preserve the undo stack
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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