Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: How can I stop a macro before it finishes?

  1. #1
    New Member
    Join Date
    Mar 2002
    Location
    Manitoba, Canada
    Posts
    22
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    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


  3. #3
    New Member
    Join Date
    Mar 2002
    Location
    Manitoba, Canada
    Posts
    22
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thank you, D. It did help. Works perfectly.
    Peter

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •