Multiple Data Validation

  • Thread starter Thread starter VoxBox-Richard
  • Start date Start date
V

VoxBox-Richard

Hello,
Is it possible to have multiple validation rules per cell? I would like it
if I could give a warning if the input was within a certain range of values,
and a stop message if it was between another.
Thank you.
Richard.
 
Can you any help me doing in using VB then? Or provide me a link explaining
how to do it.

Cheers.
R.
 
Something like this

Option Explicit

Private mmPrev As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

'reject check
If .Value < 0 Or .Value > 10 Then

MsgBox "Invalid value", vbOKOnly, "Input Error"
.Value = mmPrev
ElseIf .Value > 5 Then

MsgBox "Value may be too high", vbOKOnly, "Input Warning"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
mmPrev = Target.Value
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
Back
Top