Code to time how long a Macro takes to run...

Frinky

New Member
Joined
Feb 24, 2004
Messages
13
Hey folks,

Does anyone have any code I can stick into the end (plus maybe start) of a macro to display the length of time it took for the macro to run?

I did a quick search of the board but came up with nothing, but if there are any previous posts like this then if you could point me in the right direction it would be great...

Cheers,
f.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,886
Office Version
  1. 365
Platform
  1. Windows
Sourdust,

I don't think you meant to send him back to his original posting. In Excel, we call that a "circular reference"!
 

Sourdust

Well-known Member
Joined
Sep 15, 2002
Messages
769
Drat I tried to edit that before it was spotted but I was too slow as usual. Teach me to try to ignore piles of paperwork and hope they go away :confused:
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,886
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Sorry, Sourdust. I couldn't pass up the opportunity for a bad Excel joke! :LOL:
 

Frinky

New Member
Joined
Feb 24, 2004
Messages
13
hmmm.. I think all excel jokes are bad excel jokes...
So was there a previous post I should look at?
 

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
At the beginning of the macro put this

Dim MyTimer as Double

MyTimer = Timer

And at the end of the code put.

MsgBox Timer - MyTimer
 

Frinky

New Member
Joined
Feb 24, 2004
Messages
13
I did it this way...

Code:
    Dim dtStartTime As Date
    
    dtStartTime = Now()

    ' Main Macro code...

    MsgBox "Macro ran successfully in " & _
            FormatDateTime(Now() - dtStartTime, 3), vbInformation
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,091
Messages
5,768,039
Members
425,451
Latest member
JohnBrooksBiddle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top