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

Understanding Views

Want to see how your document will look before it's printed? Or, do you want to see what things will look like if you put ...

Discover More

Determining the Week of the Year

If you are working with dates in a macro, you may need to determine which week of the year a date falls within. This can ...

Discover More

Changing Column Width

Do you use columns in your document layout? You may want to modify the widths of various columns, and Word makes the ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Displaying Elapsed Time in Decimal Format

Want to display an elapsed time as a decimal format? It's pretty easy to do, if you know that a very simple formula is ...

Discover More

Converting UTC Times to Local Times

Dates and times are often standardized on UTC time, which is analogous to GMT times. How to convert such times to your ...

Discover More

Combining and Formatting Times

Excel allows you to store times in your worksheets. If you have your times stored in one column and an AM/PM indicator in ...

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 three minus 2?

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.