rajraj9876
10-29-2013, 09:43 AM
I have a requirement I have to write a VBA code to validate for all excel cell with negative values. In case the user enters a negative value, a message box thrown " No negative values allowed" and secondly if the user changes the value of a cell that
particular cell should become red color. Again on refresh the red color validation should disappear. I have a sample code which is giving an error
(Macro 1 - For negative value validation)
Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") < 0 Then
MsgBox "No Negative value"
End If
Target.Font.ColorIndex = 3
End Sub
(Macro 2 - For changed cell)
Private Sub Worksheet_Change(ByVal Target as Range)
Target.Font.ColorIndex = 5
End Sub
particular cell should become red color. Again on refresh the red color validation should disappear. I have a sample code which is giving an error
(Macro 1 - For negative value validation)
Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") < 0 Then
MsgBox "No Negative value"
End If
Target.Font.ColorIndex = 3
End Sub
(Macro 2 - For changed cell)
Private Sub Worksheet_Change(ByVal Target as Range)
Target.Font.ColorIndex = 5
End Sub