View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Wouter HM Wouter HM is offline
external usenet poster
 
Posts: 99
Default VBA Validation between two Times

Hi Andy,

Try this:


DataOk = True
Application.EnableEvents = False
Set C22Valrange = Range("C22")
For Each cell In Target
If Union(cell, C22Valrange).Address = C22Valrange.Address Then
If cell.Value = "" Then
DataOk = True
Else
If cell.Value = #11:00:00 AM# And cell.Value <= #11:59:00
AM# Then
DataOk = True
Else
DataOk = False
cell.Clear
cell.Locked = False
ActiveCell.Offset(-1, 0).Select
End If
End If
' Cell C22 processed,
' other cells in target irrelevant
Exit For
End If
Next cell
If Not DataOk Then
msg = "Please enter a time between 11:00 (11AM) and 11:59"
MsgBox msg, vbCritical
GoTo LeaveValidation
End If
Application.EnableEvents = True


HTH,

Wouter