custom validation formula with 2 condition

faizee

Board Regular
Joined
Jan 28, 2009
Messages
214
Office Version
  1. 2016
Platform
  1. Windows
I want to validate cell C7, with two coditions,
user can only enter Data either in time format (5:00, 19:56) or "Absent"
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Faizee
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Address = "$C$7" Then
        With Target
            If .Value = "" Then
                On Error GoTo 0
                Exit Sub
            End If
            If Not ((.Value < 1 And Format(.Value, "00:00:00") Like "##:##:##") Or LCase(.Value) = "absent") Then
                Application.EnableEvents = False
                MsgBox "Wrong input, try again", vbOKOnly
                Target.Value = ""
                Application.EnableEvents = True
            End If
        End With
    End If
    On Error GoTo 0
End Sub

Vidar
 
Upvote 0
please help in in simple formula,,
i have to copy it in whole table column,
can it be possible without VBA
 
Upvote 0
Hi
You can use Conditional formatting on the actual cell:
=OR(A1<1;A1="Absent")
First color the cell red, then in Conditional Format use "No Fill".

Vidar
 
Upvote 0
Hi
You can use Conditional formatting on the actual cell:
=OR(A1<1;A1="Absent")
First color the cell red, then in Conditional Format use "No Fill".

Vidar
You also need to make sure the cell value is not less than 0.

=OR(AND(A1>=0,A1<1),A1="Absent")

If the OP wants to make sure the time value is entered in a specific format then some form of VBA (or a macro function) will be needed.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top