tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
Further to my post here:
the code provided by Jaafar Tribak was:
I now have an additional requirement.
When running the code, if the user clicks and changes a cell on the worksheet, I want that action to be undone.
I added this:
but now when Test is running, if the user changes the value in a cell, the Worksheet_Change event kicks off but crashes on this line:
with an error message of:
How can I amend it?
Thanks
Code:
https://www.mrexcel.com/board/threads/doevent-allow-value-change-without-stopping-code.1148205/#post-5570534
the code provided by Jaafar Tribak was:
Code:
Sub Test()
Dim I As Long, CTimer As String
I = 1: CTimer = Now
Application.Calculation = xlCalculationManual
On Error Resume Next
Do Until I = 10
If CTimer <> Now Then
If Application.CommandBars.GetEnabledMso("MergeCenter") Then
Sheet1.Cells(I, 1).Value = I
I = I + 1: CTimer = Now
End If
End If
DoEvents
Loop
Application.Calculation = xlCalculationAutomatic
MsgBox "Completed"
End Sub
I now have an additional requirement.
When running the code, if the user clicks and changes a cell on the worksheet, I want that action to be undone.
I added this:
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Undo
End Sub
but now when Test is running, if the user changes the value in a cell, the Worksheet_Change event kicks off but crashes on this line:
Code:
Application.Undo
with an error message of:
Code:
Method 'undo object'_application failed
How can I amend it?
Thanks