Checking for Data Entry Errors for Times

Written by Allen Wyatt (last updated July 17, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


King notes that if a cell is formatted as hh:mm or [h]:mm and you accidentally enter 3:555 in the cell, you get 12:15 instead of 3:55. Excel is interpreting the 555 as 555 minutes, not 55 and 1/2 minutes. He wonders if there is a way to guard against such data entry errors, as he cannot get data validation to handle it.

King is correct; data validation won't handle this type of error. If you set data validation to allow Time entry into a cell and then set the bounds to be 12:00:00 am to 11:59:59 pm (so that any time is allowed), it will still accept 3:555 and misinterpret it as 3 hours and 555 minutes, or 12:15. Since 12:15 is within the allowed range of times, data validation sees no problem.

Data validation could still be used, however, if you split your time input to two cells. Allow the user to input hours into one cell and minutes into another, and use data validation to enforce acceptable input parameters for each cell. This would stop 555 from being accepted as a valid number of minutes. You could then convert the two cells into a valid time in this manner:

=A1/24+B1/(24*60)

Several subscribers suggested using a macro to check the contents of the cell and stop the typo entry. Each suggestion relied upon the Worksheet_Change event handler, which seemed very promising. None of the solutions that were provided, however, would capture the entry of 3:555 as incorrect. The reason is that by the time Excel handed control over to the Worksheet_Change event, its internal routines had already parsed the entry and changed it to 12:15. While 3:555 could be programmatically flagged and adjusted, the parsed 12:15 could not—it is still considered a valid time, so it sailed right through any of the Worksheet_Change macros.

The only macro-based solution, then, would be one that uses an inputbox for the user to enter a time which could be verified before the macro inserts it in the worksheet. This approach, however, seems much more disruptive to easy user input than to use separate minute and second cells and apply data validation to those cells.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13248) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 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

Breaking a Document Link

Word allows you to link external information into your documents. If you no longer need to maintain the active link, you ...

Discover More

Calculating the Distance between Points

Want to figure out how far it is between two points on the globe? If you know the points by latitude and longitude, you ...

Discover More

Moving Text to a New Footnote

For certain types of work, footnotes are a necessity. Word provides an easy way to create new footnotes, but what about ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Rounding to a Half Hour and Formatting the Display

Excel is quite flexible in how it allows you to format and display times. However, some formatting and displaying can ...

Discover More

Taking the Time into Account in a Formula

Need to check the current time in a formula you are putting together? It can sometimes be tricky to remember what Excel ...

Discover More

Entering Negative Times

Do you need to enter negative times into a worksheet? Excel doesn't really provide a way to do that but understanding why ...

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}] (all 7 characters, in the sequence shown) 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 four minus 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.