Checking for Data Entry Errors for Times

by Allen Wyatt
(last updated September 13, 2014)

8

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, and 2013.

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

Removing Spaces

Need to get rid of spaces in a range of cells? There are two ways you can approach the task, as described here.

Discover More

Calculating Elapsed Time with Excluded Periods

When using Excel to calculate elapsed time, there can be all sorts of criteria that affect the formulas you would otherwise ...

Discover More

Using Slashed Zeroes

To reduce the chances of confusion in presenting data, some people like to use zeroes with slashes through them. If you fall ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Rounding Time

Need to round the time in a cell to a certain value? There are a couple of ways you can do this with a formula.

Discover More

Calculating TV Time

In some industries it is necessary to work with time resolutions of less than a second. If you need to keep track of such ...

Discover More

Dealing with Midnight Ending a Day

Dealing with times in Excel is fairly straightforward, except when it comes to midnight. Some people prefer that midnight ...

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 8Mpixels. 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 6 - 3?

2014-09-16 13:16:41

Aldo

Mike ... I suggest then creating a user dialogue form where you can take full control of any users input. I does take a bit more programming skill, but you will be able to manage all input parameters including input formatting and raise errors as needed to inform the user.


2014-09-15 08:38:38

Jeff

Just be aware that data validation can be bypassed when pasting into a cell.


2014-09-15 06:46:18

Mike

Thanks for the input guys. King submitted this on my behalf. I am creating a spreadsheet to log "Attention Required Now" times in up to 40 different cells on a spreadsheet log for our Temperature Chambers, and have upwards to two dozen people making the entries. So I have to make it foolproof in regards to a fat-fingered entry of say "444" for minutes instead of the intended "44". What I ended up doing is formating all 40 of the cells to TEXT and made a range in Data Validation for the 1441 time-to-the-minute possibilities from "00:00" thru "23:59". Not what I desired, but it works.


2014-09-15 03:34:45

Wim Torfs

I use this
3 12 13 3:12:13
=TIME(A1;B1;C1)


2014-09-13 19:08:07

Bob Beechey

I am disappointed you did not try my macro which, against your statement, worked perfectly. Like Locke's suggestion, it depended upon the time entry taking place in a column pre-formatted as text. This allows validation before the macro converts it to any chosen time format.


2014-09-13 18:16:59

Locke

What about making the number format of the data entry range for time the "Text" number format. Then you could use your Worksheet_Change events to validate against 3.555 as well as reformat the valid times the way you want it to look with the macro below (Assuming the data entry column is column A).


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 Then 'Data Entry Time Input Column

If IsDate(Target.Value) Then
Target.Value = Format(TimeValue(Target.Value), "h:mm AM/PM")
Target.Interior.Pattern = xlNone
Target.Font.ColorIndex = xlAutomatic
Else
'Mimic the "Bad" range style colors
Target.Interior.Color = RGB(255, 199, 206)
Target.Font.Color = RGB(156, 0, 6)
End If

End If

End Sub


On a side note, I realized in testing this that VBA's TimeValue function appears to be superior to Excel's TimeValue worksheet function in that VBA can successfully convert "3:59p", but Excel needs it to read "3:59 p".


2014-09-13 12:15:20

Erik

If you'd rather not do math to convert the hours and minutes into an Excel serial number, Excel's built-in TIME function will do it for you:
=TIME(A1,B1,0)


2014-09-13 09:56:52

Aldo

What I do sometimes when I am doing data entry like times, or field measurements for projects, is turn on the text-to-speech feature "Speak cells on enter" in Excel. This helps me by having Excel speak the entry I inputted so I can hear the value to make sure it was entered correctly. I have the Speak cells on enter tool readily available on the Quick Access Toolbar.


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.