Data Validation

gimli

New Member
Joined
Nov 11, 2009
Messages
37
Hello all,

Trying to add multiple data validations for a cell and having hard time getting conditions to work.
Restrictions are numbers between 0 and 100 or just the text value of x. Any suggestions
would be great!

thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Assuming your validation is setup in A1, use a Custom validation setting with the following formula:
Code:
=OR(AND(A1>=0,A1<=100),A1="x")
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim i As Long, str As String
    If Target.Address = "$A$1" Then
        str = Range(Target.Address)
        If IsNumeric(str) Then
            If Val(str) < 0 Or Val(str) > 100 Then GoTo Wrong
        End If
        If Not IsNumeric(str) Then
            If str <> "x" And str <> "X" Then GoTo Wrong
        End If
    End If
    Application.EnableEvents = True
    Exit Sub
Wrong:
    MsgBox "Only allowed 0-100 or x"
    Range(Target.Address) = ""
    Range(Target.Address).Select
    Application.EnableEvents = True
End Sub
 
Upvote 0
Sorry, didn't see your post Tracy!

No biggee. Alternative solutions is what makes this site great :-)
PS: wait till you see the updated site! Been testing for 2 weeks and I love it!
 
Upvote 0
Thanks for the help...though I responded Friday....maybe didnt hit pst reply.

Anyways,
this code worked perfect.
=OR(AND(A1>=0,A1<=100),A1="x")

Is there a way to add one more validation to that code? I just want to allow integers to be entered..no decimal points.
is that doable ?

Thanks much
 
Upvote 0
Is there a way to add one more validation to that code? I just want to allow integers to be entered..no decimal points.
is that doable ?
Try
=OR(AND(A1>=0,A1<=100,IFERROR(INT(A1),A1)=A1),A1="x")
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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