Optimizing and understanding the performance of your code is key to improving efficiency, especially when running complex tasks in Excel. Below is a simple VBA macro to help you track the execution time of your code and improve your productivity!
Why should you use this?
- Track how long your macro takes to execute.
- Understand performance bottlenecks.
- Improve your VBA code efficiency
Sub RunTime_Seconds() ' To check execution time of code Dim StartTime As Double Dim timeElapsed As Double ' In seconds ' Remember the time when macro starts StartTime = Timer ' ***************************** ' Insert Your Code Here... ' ***************************** ' Calculate how many seconds the code took to run timeElapsed = Round(Timer - StartTime, 2) ' Notify user of execution time MsgBox "This code ran successfully in " & timeElapsed & " seconds", vbInformation End Sub
How It Works:
- Timer function: This VBA function returns the number of seconds elapsed since midnight. By capturing the start time with StartTime = Timer, we can subtract it from the current time after the code execution to get the elapsed time.
- Round(): We round the result to two decimal places to avoid unnecessary precision.
- The message box: It pops up a notification to inform the user about how long the macro took to execute.

Track the execution time of your code and improve your productivity
Why Use It?
By embedding this simple snippet into your workflows, you can easily gain insights into your code’s performance.
Pro Tip: To measure the performance of multiple sections of code, simply place the StartTime = Timer at the beginning of each section and MsgBox at the end to show how long each part takes!
Feel free to share how you're using this or other tips to speed up your VBA macros! Let’s make VBA even more efficient together.
Optimize Performance: Track execution times of different parts of your code.
Improve Code Efficiency: Identify slow sections and optimize them.
Better Debugging: Quickly pinpoint areas where your code may be underperforming.
By embedding this simple snippet into your workflows, you can easily gain insights into your code’s performance.
🔧 Pro Tip: To measure the performance of multiple sections of code, simply place the StartTime = Timer at the beginning of each section and MsgBox at the end to show how long each part takes!
Feel free to share how you're using this or other tips to speed up your VBA macros! Let’s make VBA even more efficient together. 🚀
OUR BLOG
Check our other top quality content posts on the blog.
Don’t wait and start
your own project with us today

Happy clients

Projects delivered
Magni dolores eos qui Ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet