Hello!
I can't figure out how to make a code loop until user input and continue if there is no input. I don't want to use Ctrl + Break, because I am interested in how many times the code ran and how long it took.
Is there a way to have the code pause and basically ask the user to stop? However, I want it to continue if I receives no input. I plan to run this code over long periods of time while I am away from my computer and want to be able to come back and stop it.
I don't mind waiting for a loop to finish to tell it to stop.
This is my code right now (Set to run just three times) :
Sub CalculateRunTime_SecondsBUDDY()
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
StartTime = Timer
Let x = 0
Do While x < 3
Calculate
x = x + 1
Loop
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
'Notify user in seconds
MsgBox "This BUDDY code ran " & x & " times successfully in " & SecondsElapsed & " seconds. Wow!", vbInformation
End Sub
My current theory is to have the line: Do While x < 3 become Do While x < y.
And somehow user input can change y, so to start I set it on a high number, but when I want it to stop, I can enter 0.
I can't figure out how to make a code loop until user input and continue if there is no input. I don't want to use Ctrl + Break, because I am interested in how many times the code ran and how long it took.
Is there a way to have the code pause and basically ask the user to stop? However, I want it to continue if I receives no input. I plan to run this code over long periods of time while I am away from my computer and want to be able to come back and stop it.
I don't mind waiting for a loop to finish to tell it to stop.
This is my code right now (Set to run just three times) :
Sub CalculateRunTime_SecondsBUDDY()
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
StartTime = Timer
Let x = 0
Do While x < 3
Calculate
x = x + 1
Loop
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
'Notify user in seconds
MsgBox "This BUDDY code ran " & x & " times successfully in " & SecondsElapsed & " seconds. Wow!", vbInformation
End Sub
My current theory is to have the line: Do While x < 3 become Do While x < y.
And somehow user input can change y, so to start I set it on a high number, but when I want it to stop, I can enter 0.