PDA

View Full Version : Outputing the time taken for a calculation



wes2706
04-04-2017, 09:58 PM
I am running a macro within Excel, and would need to show the time taken to run the macro by way of message box (Msgbox).
So I need to record the time that the macro start- say T1.
Time that the macro ends- say T2
Take the difference and report it in minutes and seconds..
(it takes about a minute and a half….sometimes less than a minute)
The msgbox should give a message like this:
“Great! All the columns are successfully extracted.
This task took X minutes and Y seconds”.
If it’s less than 1 minute….just
“This task took Y seconds”.
Can someone please help?

mancubus
04-04-2017, 11:54 PM
try



Sub vbax_59088_code_execution_time()

Dim tStart As Double, tEnd As Double

tStart = Timer

'your whole procedure here
'
'
'

tEnd = Timer

MsgBox "Completed in: " & ((tEnd - tStart) \ 60) & " minutes, " & ((tEnd - tStart) Mod 60) & " seconds."

End Sub