Skip to Content
0
Former Member
Oct 29, 2013 at 04:03 PM

VBA code for Validation

138 Views

HI All,

I have a requirement I have to write a VBA code to validate for all input cell in an input form (EPM 10) 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.

Now that I had already tried with the validation function in SP13 which did not give the desired result and so I have decided to code ,

Now I have a problem I need to code the excelVBA that I have to apply the validation code only on the input cells How do I do that ? the sample code is below

Dim EPMex As New FPMXLClient.EPMAddInAutomation

(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

Thanx