Data Validation : Allow only time input

Neil Hall

New Member
Joined
Jul 2, 2015
Messages
5
I have a form that different teams return to me giving their total hours spent each day on different activities. Currently some people for example 1 and a half hours work type 1.5 or some do 1:30.
I wish to limit input to time format ie 1:30.
However these totals can go over 24 hours. The cell format is already [h]:mm and I want an error message if they were to type in 1.5.
I’ve tried different things such as 10/02/07 15:00 but it still allows eg 1.5 to be input.
Not sure if the validation would be that : needed to be input rather that looking at actual time formatting.
I’ve searched different threads and not found an answer.
I’m using 2007.
Any help is gratefully received.
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

theBardd

Rules violation
Joined
Jan 21, 2012
Messages
912
Why not let them input as they wish and convert 1.50 to 1:30 in a change event?
 

Neil Hall

New Member
Joined
Jul 2, 2015
Messages
5
This is what I have to do now, but there is always an element of doubt that 1.5 is actually 1:30 or is it 1 hour 50 minutes. I wish to remove that doubt and force just time format input. If possible.
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,571
Office Version
365
Platform
Windows
Try this:
Put the code in the sheet's code module. Change 'Range("A2:A10")' to suit.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2:A10")) Is Nothing Then
        If Target.Cells.Count = 1 Then
        
            If Target.Text Like "#:##" Or Target.Text Like "##:##" Then
            'do nothing
            Else
            Target.Activate
            MsgBox "You must use this format 'hour:minutes', example:  2:05" & vbCr & _
            "(it means 2 hour & 5 minutes)"
            End If
        End If
    End If
End Sub
Note: if the total hours could be more than 99 hour then we need to modify the code.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,211
Messages
5,485,372
Members
407,499
Latest member
Dman25

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top