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

AutoFilling with Weekdays

Need to fill a range of cells with the days of the week? Excel makes it easy to do so using AutoFill.

Discover More

Getting Rid of Choppiness in Justified Text

Justified text doesn't always produce the best-looking results. Here's how to avoid some of the choppiness that can occur.

Discover More

Running Macros Based on Keywords

Wouldn't it be great if Word could execute a macro every time someone typed in a particular keyword or phrase? Word may not ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Dealing with Small Time Values

It is no secret that you can store time values in an Excel worksheet. But do you really know how small of a time value you ...

Discover More

Automatically Entering a Data Entry Time

Excel worksheets can be used to keep track of all sorts of information. You may want to use it, for instance, to track ...

Discover More

Converting Numeric Values to Times

If you have a bunch of times entered into cells without the colon between the hours and minutes, chances are good that Excel ...

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 7 - 1?

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.