Log in

View Full Version : Solved: Data Validation Negitive



BENSON
08-27-2009, 10:47 PM
What should I enter in the Data Validation drop box to allow user to only enter negitive numbers ie numbers less than zero like -1

Thks

Oorang
08-27-2009, 11:40 PM
Set "Allow" to either "Whole Number" or "Decimal". Then set "Data" to "Less Than". Finally set "Maximum" to 0. You can also do it via VBA, but it's usually not necessary to use VBA for this task.
Sub Example()
Dim rng As Excel.Range
Set rng = Excel.ActiveSheet.Range("E6")
With rng.Validation
.Delete 'Clear any old validation.
.Add xlValidateWholeNumber, xlValidAlertStop, xlLess, "0"
.ErrorTitle = "Invalid Entry"
.ErrorMessage = _
"This cell only accepts values less than zero (Negative Numbers)."
End With
End Sub