Undo VBA Action

jlynch

New Member
Joined
Mar 16, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Web
Currently, when a cell in columns A, B, C, E, or F is updated, the cell in column D of that row will return the date/time of the last update.

However, I am unable to "undo" any changes made within the range. Is this possible?


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myTableRange As Range
Dim myUpdatedRange As Range

'Your data table range
Set myTableRange = Range("A:C,E:F")

'Check if the changed cell is in the data tabe or not.
If Intersect(Target, myTableRange) Is Nothing Then Exit Sub

'Stop events from running
Application.EnableEvents = False

'Column for last updated date/time
Set myUpdatedRange = Range("D" & Target.Row)

'Update the updated date/time value
myUpdatedRange.Value = Now

'Turn events back on
Application.EnableEvents = True
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
What exactly do you mean with I am unable to "undo", are you trying to use Ctrl+Z ? or do you mean that when you delete data within the range column D doesn't go blank ?
 
Upvote 0
What exactly do you mean with I am unable to "undo", are you trying to use Ctrl+Z ? or do you mean that when you delete data within the range column D doesn't go blank ?
Hi Rollis13,

I can’t perform Control + Z.

If I edit any cell in columns A to F, I am unable to go back to the previous version before the macro action.
 
Upvote 0
Normally, you can't undo something that was performed by a macro unless you save the previous state of the sheet prior to running the macro.

In your case, you may be able to do an application.undo.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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