Automatically Entering a Data Entry Time

by Allen Wyatt
(last updated March 28, 2020)

12

Donna needs to keep a log of activity that occurred throughout the day at her dispatch center. When a call comes in over the radio, she needs to document who, what, why, etc. She also needs to document the time (in 24-hour format) that the call came in. Donna currently does all this on paper. She would like to create a worksheet that she can type into and have the time stamp automatically populate as soon as she enters text into the cell next to it in that row. When the cell next to it is empty, she wants her time stamp cell to be blank. This way she can save time from checking the clock to write down the time.

In approaching this problem, let's assume that you want the time stamp to go into column A and you'll be entering your "who, what, why," and other info starting in column B. The simplest way to go about this is to use Excel's built-in shortcut for entering the current time: press Shift+Ctrl+; (that's a semicolon). Provided the cell is formatted to show times in 24-hour format, you'll see the current time as you want it.

If you want a more automatic approach, you might think that you could use a simple formula in column A, such as this:

=IF(B2<>"", NOW(), "")

While this will enter a time into column A if the corresponding cell in column B contains something, it won't give satisfactory results because of how the NOW function works. Remember that the function always returns the current time. Thus, anytime the worksheet is recalculated, the contents of cell B2 are checked. If there is something there, then the NOW function is called, returning the current time of the recalculation. This means that the time shown in the column A cell containing this formula will always be changing; it won't be a true time stamp.

You could, however, make the formula in column A a bit more complex, in this manner:

=IF(B2<>"", IF(A2="",NOW(),A2), "")

The very first time you enter this, it is likely you'll get an error because the formula is circular. In other words, the formula references the cell in which the formula is placed. (In this case, the formula goes into cell A2 and also references cell A2.) To make this formula work properly, you need to follow these steps:

  1. Display the Excel Options dialog box. (In Excel 2007 click the Office button and then click Excel Options. In Excel 2010 or later versions display the File tab of the ribbon and then click Options.)
  2. Click Formulas at the left side of the screen. (See Figure 1.)
  3. Figure 1. The Formulas area of the Excel Options dialog box.

  1. Make sure the Enable Iterative Calculation check box is selected.
  2. Click OK.

Now, whenever you put something into cell B2, the time is entered automatically into cell A2. However, the time is only put there if cell A2 was previously blank. If it wasn't (meaning it already contained a time), then the current contents of cell A2 remain in place.

If you don't want to allow circular references (by turning on iterative calculations), then the best approach is going to be through a macro. You can use the Worksheet_Change event to automatically enter a time into column A whenever something is entered into column B.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rInt As Range
    Dim rCell As Range
    Dim tCell As Range

    Set rInt = Intersect(Target, Range("B:B"))
    If Not rInt Is Nothing Then
        For Each rCell In rInt
            Set tCell = rCell.Offset(0, -1)
            If IsEmpty(tCell) Then
                tCell = Now
                tCell.NumberFormat = "mmm d, yyyy hh:mm"
            End If
        Next
    End If
End Sub

To set up the macro, right-click on the worksheet tab and choose View Code. You can then place the macro into the code window that is displayed. (This places the macro in the ThisWorksheet module, which is required as it is an event handler that is executed whenever something in the worksheet changes.)

The macro checks to make sure that something is actually being entered into column B. If so, then the tCell variable is set to the corresponding cell in column A. If nothing is already in that cell, then the current date and time is placed there. If you just want the time, then change the innermost part of the macro to this:

                tCell = Time
                tCell.NumberFormat = "hh:mm"

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13233) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Separating Names into Individual Columns

If you have a list of names in a column, and you want to separate those names into individual cells, there are several ...

Discover More

Finding the Lowest Numbers

Need to find the lowest numbers in a range of values? It's easy to do using the SMALL worksheet function, or you can use ...

Discover More

Filtering to a Date Range in the Past

If you have a large number of data records, each with an associated date, you might want to filter that data so you see ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Shortcut to Enter GMT

Entering the current time into a cell is easy, as Excel provides a built-in shortcut to accomplish the task. Here's a ...

Discover More

Counting Times within a Range

Excel allows you to easily store dates and times in your worksheets. If you have a range of cells that contain times and ...

Discover More

Determining If a Date and Time is within Working Hours

Excel is great at working with times and dates. Sometimes, though, it can be a bit tricky to figure out how to work with ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven more than 0?

2020-08-03 13:12:52

J. Woolley

You might be interested in my TimeStamp(Target) function that uses an unthreaded Comment (a.k.a. Note) to time stamp any cell whenever that cell's value changes. For example, to time stamp cell B2 whenever its value changes, put this formula in any cell C on the same worksheet:
=TimeStamp(B2)
That formula returns Null if C is B2; otherwise, it returns this text:
TimeStamp($B$2)
When the value of cell B2 changes, a new time stamp Comment is added to cell B2 replacing any previous Comment. If cell B2 is on Sheet1, then this formula can be in any cell of any other worksheet in the same workbook:
=TimeStamp('Sheet1'!B2)
That formula returns this text:
TimeStamp('Sheet1'!$B$2)
The function does not need to be alone in a formula; it can be part of a more complex formula such as:
=HYPERLINK("#B2",TimeStamp(B2))
That formula in cell C (where C is not B2) creates a link to cell B2 and returns this text:
TimeStamp($B$2)
The TimeStamp function should be located in a Code Module of the workbook where it is used. If the function is located in Excel's PERSONAL.XLSB or an Add-In but used in another workbook, then all of that workbook's time stamps will update each time it is opened.
The TimeStamp function can be downloaded from My Excel Toolbox at https://sites.google.com/view/MyExcelToolbox


2020-08-01 04:56:26

Peter Atherton

Jarred, Look up Date Serial for detailed description. Dateserial start from 1 and are added to for each day that passes. Enter 1 and format as a date and this will tell you when your dates start. Time is a fraction of a day the formula =TIMEVALUE("6:00") returns 0.25


2020-08-01 04:34:57

Peter Atherton

If you want to enter the current date or time use these shortcuts.
Date: Ctrl +;
Time:= Ctrl + Shift + :

(see Figure 1 below)

Figure 1. Date and Time with functions


2020-07-31 14:49:58

Jared

When I use this formula (and the "correction attempt" below) I get 44043. Or, more recently, 44043.5707. The date is 7-31-20 and the time is 1:48pm. I cannot figure out how 44043.5707 translates to that date, I feel like it doesnt.

I have Donna's issue exept I don't really need the time. I just want to know the date an "idea" was entered into the spreadsheet so we can keep track of how long an item has been there. Short of entering the date manually. I don't want it to change if I update the or add to the ideas.


2020-07-22 05:25:07

ahmad elsarji

hello

im making this system so i want a bit of help concerning the time.
this is the closest thing to what i need, but im guessing its something other than the now() function

* =IF(B2<>"", NOW(), "") *

i have tried using now() and time and today formulas but the thing is its updating for all the cells below to time now if you know what i mean
i want the time when i entered information in B2 i dont want it to keep on updating every time i enter information in column B

thanks in advance


2020-06-11 21:16:28

John

Hi,

Is there a way to use this Macro code but make the timestamp update when new information is entered into the B cell?
This is a shared workbook so people add text information without removing the existing text.

Thanks,
John


2020-04-29 07:31:31

Peter Atherton

James
Your format may be wrong. To display Date & Time use the custom formt dd/m/yyyy h:mm
If you only want the time change the format to [h]:mm:ss
However, the formula seems to display the value in B15 when it is not empty. You might find this better:
=IF(AND(A23<>"", B23=""),NOW()-INT(NOW()), "")
HTH


2020-04-28 05:12:08

james

When I enter the formula the date keeps coming back 0-Jan-1900, it won't display correctly. Now if the referenced cell is blank, it displays blank as it's supposed to. Here is my formula =IF(A15<>"", IF(B15="",NOW(),B15), "") I believe it's exactly as above. Do I need a space or remove a space somewhere? I'm not sure what I'm doing wrong. I'm using Excel 2016. Thanks for any advice why this is happening. James


2020-04-21 10:47:15

J. Woolley

@Varghese
Change the first line of the macro from
Private Sub Worksheet_Change(ByVal Target As Range)
to
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
and put the macro in the ThisWorkbook class. (In Visual Basic Editor, right-click ThisWorkbook and pick View Code.) The new macro will apply to every sheet in the workbook.


2020-04-21 02:02:00

Varghese

Hi,
How to make it (Automatically Entering a Data Entry Time) to use the entire workbook rather than a single sheet any method ?

Cheerfully

Varghese


2020-03-30 16:13:55

Allen

Peter,

Two things. First, about the focus of this site relative to Excel for the Mac. You will find, in this regard, the FAQ helpful, here:

https://excelribbon.tips.net/faq.html

You'll want to pay particular attention to the 3rd Q&A combo.

Now, as to how you get to these sort of settings on the Mac. You will need to click on the Excel menu, then choose Preferences. That displays the Excel Preferences dialog box from which you should then click Calculation.

Hope that helps, Peter.

-Allen


2020-03-30 12:53:03

Peter Clarke

In your step-by-step method of displaying a sustaining date and time in a cell you say, "Display the Excel Options dialog box. (In Excel 2007 click the Office button and then click Excel Options. In Excel 2010 or later versions display the File tab of the ribbon and then click Options.)". I am running Excel for Mac 2019 - version 16.35, Product ID: 04242-000-000004, and I cannot see where the 'File tab of the ribbon' is. Nor can I find an Options anywhere but AutoCorrect Options. Are your tips and assistance only relevant to Windows OS products? I was under the impression when I signed up for your tips that they were Mac OS relevant also. Please assist.

Kind regards,
Peter Clarke - plclarke@xplornet.com


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.