Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Error Checking

Status
Not open for further replies.

teebird

Technical User
Dec 11, 2001
239
I have this code in an Add function but it is not working the way I want.

If Len(Range("B5").Value) = 0 Then
MsgBox "Please add the Patient's HRN!", vbOKOnly, "HRN Error"
Range("B5").Select
Range("B5").ClearContents
Exit Sub
Else: ws.Cells(orow, "A").Value = Range("Input!B5")
End If

If Len(Range("B6").Value) = 0 Then
MsgBox "Please add the Patient's Name!", vbOKOnly, "Name Error"
Range("B6").Select
Range("B6").ClearContents
Exit Sub
Else: ws.Cells(orow, "B").Value = Range("Input!B6")
End If

If Len(Range("B7").Value) = 0 Then
MsgBox "Please add the Patient's Date of Birth!", vbOKOnly, "DOB Error"
Range("B7").Select
Range("B7").ClearContents
Exit Sub
Else: ws.Cells(orow, "C").Value = Range("Input!B7")
End If

Each time I click the OK button on the messagebox to close the dialog box, the previous value is entered, and the next value is put in the next cell (next column).

So in my spreadshhet I end up with
Column 1 - Column 2 - Column 3
120 -
120 - Charlie Brown -
120 - Charlie Brown - 15/04/1996 -

When I really want 120 Charlie Brown 15/04/1996
Any help woiuld be great...

Tee
 
Try stepping through your code with F8. You can set Breakpoints in your code on individual lines (no Dim lines, or compile lines) with the F9 key (toggles) or clicking the left bar, directly left of the code/text pane in the VBEIDE.

I suggest you have your VBE only open about half-way so you can view your worksheet at the same time and see what it's doing.

-----------
Regards,
Zack Barresse
 
Also, you don't need to select the cell before clearing the contents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top