Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,779
- Office Version
- 2016
- Platform
- Windows
Hi all . Consider the simple code below :
The code just updates Cell A1 with the current time. The Doevents is there so the application doesn't freeze and the user is able to edit the sheet while the loop is running.
The problem ,as we know, is that if the user edits a cell the loop is aborted.
Is there a way to have a loop that continues even after edting the worksheet ?
I know one could for example use the OnTime Method in the above scenario to overcome the issue in this particular situation but I am looking for a more generic solution that always works whenever using a Do Loop structure.
Any ideas ?
Code:
Private bStopMacro As Boolean
Sub StartLoop()
bStopMacro = False
Do
Range("a1") = Format(Time, "hh:mm:ss")
DoEvents
Loop Until bStopMacro
End Sub
Sub ExitLoop()
bStopMacro = True
End Sub
The code just updates Cell A1 with the current time. The Doevents is there so the application doesn't freeze and the user is able to edit the sheet while the loop is running.
The problem ,as we know, is that if the user edits a cell the loop is aborted.
Is there a way to have a loop that continues even after edting the worksheet ?
I know one could for example use the OnTime Method in the above scenario to overcome the issue in this particular situation but I am looking for a more generic solution that always works whenever using a Do Loop structure.
Any ideas ?