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...
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

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
 

Forum statistics

Threads
1,140,941
Messages
5,703,301
Members
421,290
Latest member
james90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top