Inputbox

Ampleford

Active Member
Joined
Mar 26, 2002
Messages
380
I have an inputbox which asks for some info, drops that on a spread then prints the spread based on that info. All well - except when you press the "Cancel" button - it still runs the Macro... What is the syntax to make it stop ?

My script for the macro so far is :-

Prdno = InputBox("Please enter the Period you wish to print", "Enter Period")
Sheets("Register").Select
Range("A1:C1").Select
ActiveWorkbook.Unprotect
Sheets("Data").Visible = True
Sheets("Data").Select
Range("e1").Select
Selection.FormulaR1C1 = Prdno
Sheets("Register").Select
Range("D1:E1").Select
ActiveCell.FormulaR1C1 = "=Data!RC[2]"~~~~~~~~~ Etc

I know there needs to be a line after the first which acknowledges and actions the "Cancel" button...

Help please ?

:(
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If cancel is pressed a zero-length string is returned, so just add the line below after calling your inputbox: -

Prdno = InputBox("Please enter the Period you wish to print", "Enter Period")
If Prdno="" Then Exit Sub
' Rest of macro
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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