Code error with input box

R

raw

Hi Guys

Here is my code 4 a print box (how many copies would you like)

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim no_of_copies As Integer

Select Case True
Case OptionButton1
Set ws = Sheets("verticalordersheet")
Case OptionButton2
Set ws = Sheets("verticalvanesordersheet")
End Select

no_of_copies = Application.InputBox("How many copies do you wish t
print?", , 1)

ws.PrintOut copies:=no_of_copies, Collate:=True


Close

End Sub

But i get 2 errors

1. is "Run-time error 91" This happens when you do not select a optio
button

2. is "Run-time error 1004" This happens when you press the cance
button

Can you help

Thank
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim no_of_copies As Integer

Select Case True
Case OptionButton1.Value
Set ws = Sheets("verticalordersheet")
Case OptionButton2.Value
Set ws = Sheets("verticalvanesordersheet")
Case Else
Exit sub
End Select

no_of_copies = Application.InputBox("How many copies do you wish to
print?", , 1)
if no_of_Copies = 0 then exit sub
ws.PrintOut copies:=no_of_copies, Collate:=True

' not sure what close is supposed to be
Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top