Reputation: 63
I'm currently using the following code to determine the time which it takes for a certain macro to run.
Sub Timer ()
Dim StartTime As Double
Dim SecondsElapsed As Double
StartTime = Timer
'Some macro executed
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub
Now, I want to use this timer for several macros which are executed in a row using a button. I'm looking for something like:
<Button>
'Dim StartTime As Double
'Dim SecondsElapsed As Double
StartTime = Timer
Macro1
Macro2
Macro3
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
<Button>
Upvotes: 0
Views: 349
Reputation: 358
You can just call your macros from within your main timer code
Sub Timer ()
Dim StartTime As Double
Dim SecondsElapsed As Double
StartTime = Timer
call Macro1()
call Macro2()
call Macro3()
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub
If you wanted to know how long each one took individually just declare a SecondsElapsed variable for each Macro and populate it after each Call statement.
Upvotes: 2