How can I stop a macro before it finishes?

Mood

New Member
Joined
Mar 12, 2002
Messages
22
I have a macro that calls up a series of about 12 inputboxes. The first inputbox opens, waits for me to type the numbers, I press enter, and then it goes to another cell and the next inputbox opens up, etc. The problem I have is that there is no way for me to stop or cancel the macro between the different inputboxes (before the "Range.Select" is executed.) Is there a way of pressing the ESC key to stop or cancel the macro? Here is part of the code for the macro:

Range("B4").Select
MyNum2 = Application.InputBox(Prompt:="REGULAR HOURS", Title:="HOURS OF WORK", Default:="80", Type:=1)
ActiveCell.FormulaR1C1 = MyNum2

CANCEL HERE

Range("C4").Select
MyNum3 = Application.InputBox(Prompt:="TIME AND ONE HALF HOURS", Title:="HOURS OF WORK", Default:="4", Type:=1)
ActiveCell.FormulaR1C1 = MyNum3

or CANCEL HERE etc.

Thanks for any help

Peter
This message was edited by Mood on 2002-03-14 09:21
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I have a macro that calls up a series of about 12 inputboxes. The first inputbox opens, waits for me to type the numbers, I press enter, and then it goes to another cell and the next inputbox opens up, etc. The problem I have is that there is no way for me to stop or cancel the macro between the different inputboxes (before the "Range.Select" is executed.) Is there a way of pressing the ESC key to stop or cancel the macro? Here is part of the code for the macro:

Range("B4").Select
MyNum2 = Application.InputBox(Prompt:="REGULAR HOURS", Title:="HOURS OF WORK", Default:="80", Type:=1)
ActiveCell.FormulaR1C1 = MyNum2

CANCEL HERE

Range("C4").Select
MyNum3 = Application.InputBox(Prompt:="TIME AND ONE HALF HOURS", Title:="HOURS OF WORK", Default:="4", Type:=1)
ActiveCell.FormulaR1C1 = MyNum3

or CANCEL HERE etc.

Thanks for any help

Peter

You wouldn't be able to press a key because the time taken to between executing the lines:-

ActiveCell.FormulaR1C1 = MyNum2

and

Range("C4").Select

would be almost instant.

The way to exit a sub is to use

Exit Sub

If you want to exit the procedure if the user presses Cancel on the inputbox is to use this:-

MyNum2 = Application.InputBox(Prompt:="REGULAR HOURS", Title:="HOURS OF WORK", Default:="80", Type:=1)
If CStr(MyNum2)="False" Then Exit Sub

HTH,
D
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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