Popup for cell change
Maybe something like this then:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False
If Target.Count = 1 And Target.Column 1 _
And IsNumeric(Target.Value) Then
If UCase(Target.Offset(0, -1).Value) = "DR" Then
If Target.Value < 0 Then
MsgBox "Debit must be positive"
Target.Value = ""
End If
ElseIf UCase(Target.Offset(0, -1).Value) = "CR" Then
If Target.Value 0 Then
MsgBox "Credit must be negative"
Target.Value = ""
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub
This is worksheet event code. Right click the sheet tab, select View
Code and paste the code in there.
Hope this helps
Rowan
Craig wrote:
I'm using Excel 2000. I have a spreadsheet where a user enters numbers for
debits and credits. I'd like to have a popup appear when the user enters a
value incorrectly - ie, debits have to be entered as a positive number,
credits have to be negative.
Also, is there a way to erase or undo the previous entry?
I'm thinking the worksheet_change event is needed here, but what I've tried
doesn't seem to work:
Private Sub Worksheet_Change(ByVal Target As Range)
if ActiveCell.Offset(0, -1).Value = "Debit" and Range("ActiveCell.Value
<1 Then
MsgBox "The number entered needs to be positive"
Elseif ActiveCell.Offset(0, -1).Value = "Credit" and
Range("ActiveCell.Value 1 Then
MsgBox "The number entered needs to be negative"
End If
End Sub
Thanks for any and all help.
|