Consulting

Results 1 to 3 of 3

Thread: validation for Negative number

  1. #1

    validation for Negative number

    Hi Experts,
    I have to write a VBA code to validate for all active cell with negative values. In case of a negative value entered, a message box thrown " No negative values allowed" and the that particular cell should become red color. Again on refresh the red color validadation should disappear.
    Thanks
    Raj

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,050
    Location
    Surely all you need to do is data validation for the range of cells and if its value is less than zero turn the value red. However, if you persist with reinventing the wheel, simply record your steps with the macro recorder and edit the code to suit.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    thanks a lot, but still am stuck with one feature when the cell is input , the negative validation should work with the input cell becoming "red" how do I bring this feature in the validation and this for all active cell. This is the macro code below

    With Selection.Validation
    .Delete
    .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
    Operator:=xlGreater, Formula1:="0"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = "no "
    .InputMessage = ""
    .ErrorMessage = "nooo"
    .ShowInput = True
    .ShowError = True
    End With
    Range("G9").Select
    With Selection.Validation
    .Delete
    .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
    Operator:=xlGreater, Formula1:="0"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = "no"
    .ErrorTitle = "no "
    .InputMessage = "no values below 0"
    .ErrorMessage = "nooo"
    .ShowInput = True
    .ShowError = True
    End With
    Range("G9").Select
    End Sub
    Last edited by rajraj9876; 10-27-2013 at 06:56 PM. Reason: additional content

Posting Permissions

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