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.
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!
Dealing with times in Excel is fairly straightforward, except when it comes to midnight. Some people prefer that midnight ...
Discover MoreDo you need to enter negative times into a worksheet? Excel doesn't really provide a way to do that but understanding why ...
Discover MoreExcel is quite flexible in how it allows you to format and display times. However, some formatting and displaying can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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 © 2024 Sharon Parq Associates, Inc.
Comments