Creating an Error Message Box

newclasshero

New Member
Joined
Sep 1, 2006
Messages
46
I have a command button linked to this macro. It will print my Cheque Requisition forms except if the Invoice Number is mising from "B90". However it does not seem to want to run. Here it is:

Private Sub CommandButton3_Click()
If Sheets("Voucher").Cell("B90") >= 0 Then
Sheets("Voucher").Range("A64:J94").Select
Selection.PrintOut Copies:=1, Collate:=True
If Sheets("Voucher").Cell("B90") = 0 Then
MsgBox ("Please Input Invoice #.")
End If
End Sub

It worked great for print the Document before I put in the if statement and MsgBox info.

ps. I am not that familiar with MsgBox's and I think that may be why it is screwing up...
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
The way you have it written, you are missing an End If. Unless the IF statement is all on one line (simplistic example: If A=2 Then "OK"), you need an End If for each If.

Just use one If statement:
Code:
Private Sub CommandButton3_Click()
If Sheets("Voucher").Cell("B90") >= 0 Then
     Sheets("Voucher").Range("A64:J94").Select
     Selection.PrintOut Copies:=1, Collate:=True
Else
     MsgBox "Please Input Invoice #."
End If

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,113,862
Messages
5,544,727
Members
410,630
Latest member
JFORTH97
Top