Urgent: Troubleshoot Cancel and Exit button on InputBox on macro

jdmc45

Board Regular
Joined
May 8, 2011
Messages
146
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am very close to having a macro good to go for printing off certain worksheets, with the exception of having troubleshooted the cancel and exit button on the inputbox when asking for the number of copies. Could you please help me on this?

Code is below:

Code:
Sub Printing()
Dim NumCopies As Long
Dim ans As String

NumCopies = InputBox("Please enter number of copies", "Print Staff Lists")
ans = MsgBox("Are you sure you want to print " & NumCopies & "?", vbQuestion + vbYesNo, "Print pages")

If ans = vbNo Then
Exit Sub
 
Else
    Worksheets("1").PrintOut Copies:=NumCopies
    Worksheets("2").PrintOut Copies:=NumCopies
    Worksheets("3").PrintOut Copies:=NumCopies
    Worksheets("4").PrintOut Copies:=NumCopies
    Worksheets("5").PrintOut Copies:=NumCopies
End If
 
End Sub

After NumCopies line I have added

If NumCopies = "" Then Exit Sub

but still receive the error message "Run time error 13, type mismatch"

I need this asap any help will be much appreciated!

Thanks,

James
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello jdmc45,

An other option option is to use Val to convert the text into a number.
Code:
Worksheets("1").PrintOut Copies:=Val(NumCopies)
</pre>
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

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