Consulting

Results 1 to 2 of 2

Thread: Solved: Data Validation Negitive

  1. #1
    VBAX Contributor
    Joined
    Dec 2006
    Posts
    193
    Location

    Solved: Data Validation Negitive

    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

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    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.
    [VBA]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[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •