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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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
Back
Top