You may want to use Excel to record the elapsed time for different events. There are two ways that this can be approached: either native, within Excel, or with a macro.
If you don't want to use a macro, you can easily set up three columns for your timing. The first column can be used to record the start time, the second column the end time, and then the third column the elapsed time (calculated by using a formula that subtracts the start time from the end time). In order to record times, you select a cell in either the start time or end time columns and press Ctrl+Shift+: (the colon). Excel enters the current time in that cell.
If you want to use a macro that simply returns the elapsed time, then you can use the following:
Public Sub TimeIt() Dim vStartTime As Date vStartTime = Time MsgBox Prompt:="Press the button to end the timing" & vbCrLf _ & "Timing started at " & Format(vStartTime, "hh:mm:ss"), _ Buttons:=vbOKOnly, _ Title:="Time Recording Macro" ActiveCell.Value = Time - vStartTime End Sub
This macro records a start time (in vStartTime), and then displays a message box. When you click on the message box button, the difference between the current time and the start time is stored in the current cell. (You need to make sure the current cell is formatted with one of the time formats.)
The above macro works very well for recording short events during which you don't need to use Excel for other tasks. If you need to record longer events, then a different approach is in order. The following macros work in tandem. The first one records a start time; that is all it does. The second one uses that recorded time to calculate an elapsed time which is placed in the currently selected cell.
Global vStTime Sub StartTiming() vStTime = Time End Sub Sub EndTiming() ActiveCell.Value = Time - vStTime End Sub
You could easily assign these two macros to the Quick Access Toolbar or to different toolbar buttons that would, respectively, start and stop the timing process.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11193) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Using Excel for Timing.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
When you use a formula to come up with a result that you want displayed as a time, it can be tricky figuring out how to ...
Discover MoreEntering the current time into a cell is easy, as Excel provides a built-in shortcut to accomplish the task. Here's a ...
Discover MoreDealing with times in Excel is fairly straightforward, except when it comes to midnight. Some people prefer that midnight ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2016-10-04 05:13:26
Tanya
How do i get excel to included the seconds, when i press Ctrl+Shift+: (the colon). Excel enters the current time in that cell.I need seconds too.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments