help on error checking (basic)

F

forevercalz

im a newbie to this excel programing..
currently..i use the function to sum up cells..
However i need to do error checking...if the sum of A1 and A2 is more
than 1..it will not allow A2 to input the number. how to do that?

thanks in advance!
 
B

Bob Phillips

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A2"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Value + .Offset(0, -1).Value > 1 Then
MsgBox "Sum invalid"
.Value = ""
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"forevercalz" <[email protected]>
wrote in message
news:[email protected]...
 
F

forevercalz

Well thanks..however..your code only apply to validate one cell at
time..as i have many columns...A1 A2 A3 A4 A5 to validate....so i hav
to paste 5 times the code each with different variable??? is there
way to declare all the columns in one variable?



------------------------------------------------------------------------
forevercalz's Profile:
http://www.excelforum.com/member.php?action=getinfo&userid=28931
View this thread[/QUOTE]
http://www.excelforum.com/showthread.php?threadid=486754
 
B

Bob Phillips

You originally said that if the sum of A1 and A2 is more than 1..it will not
allow A2 to input the number. If this is so, which cell will be checked with
A1, as there is no previous row.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"forevercalz" <[email protected]>
wrote in message
Well thanks..however..your code only apply to validate one cell at a
time..as i have many columns...A1 A2 A3 A4 A5 to validate....so i have
to paste 5 times the code each with different variable??? is there a
way to declare all the columns in one variable?

http://www.excelforum.com/member.php?action=getinfo&userid=28931
View this thread: http://www.excelforum.com/showthread.php?threadid=486754
[/QUOTE]
 
Top