

If Not Intersect(Target, rng) Is Nothing ThenĪfter you put this procedure onto the worksheet module, double-click in an empty Start or Stop time cell. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
#Timetracker excel code
The code only runs if you double-click an empty cell (.Value = “”) in the TimeEntry range. The following code is stored on the code module for the worksheet where you want to enter the times. That range is selected in the screen shot below – cells B2:C4

In this example, the start and stop times will be entered in a range named TimeEntry. So, to make it easier, you can use Event code, and automatically run the macro when a cell is double-clicked. It’s not very convenient to manually run a macro when you want to enter the current time. Sub EnterTime()Įnter the Current Time with a Double-Click The time will automatically include hours, minutes, and seconds. Instead of using the default shortcut for entering the current time, you can use Excel VBA to enter the time.įor example, you can select a cell on the worksheet, and run the following macro, to enter the current time in the active cell.

So, if you’re keeping track of very short tasks, or need precision to the second, the keyboard shortcut for entering time won’t help you. All the times are entered as 00 seconds, as you can see in the screen shot below. One problem with using the keyboard shortcut to enter the current time is that it doesn’t include the seconds in the time. Then, Excel formulas can calculate the total project time, based on the start and stop times. Last week, we saw the steps for entering project start and stop times in Excel, by using keyboard shortcuts.
