+ Reply to Thread
Results 1 to 20 of 20

Suspending a macro

  1. #1
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Suspending a macro

    Has anyone discovered a way to suspend a running macro to allow input to a cell on the active worksheet? Upon entry control would be returned to the macro for manipulation of the entered value.

    While not a macro per se the worksheet_change event works for me. This has been more than a simple math trainer for my grandson but a journey of discovery for me. Thank you all for your help. The basic code that I can build upon follows...

    Please Login or Register  to view this content.
    Oh! In my zeal to get an answer I mistakenly cross posted to another forum without proper notice. (rtfms). I bear the cross of my 5 demerit points with suitable shame. Thanks again all.
    Last edited by OldTim; 08-17-2010 at 01:34 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    Welcome to the forum.

    See the InputBox function.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by shg View Post
    Welcome to the forum.

    See the InputBox function.

    Thanks shg. I am looking for a different approach if at all possible in VB. I don't want an InputBox cluttering up my spreadsheet. Any other ideas?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    You can use a MsgBox to prompt the user to make an entry.

  5. #5
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by shg View Post
    You can use a MsgBox to prompt the user to make an entry.
    more clutter on my spreadsheet As far as I can tell MsgBox uses canned responses and does not allow entry of the value that I would otherwise enter on the spreadsheet. I was hoping to find a subtler solution. I really appreciate you taking the time to respond to my post. Thanks

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    As is becoming apparent, I don't know what you're trying to do.

    You can select a cell, put a prompt in it, exit the sub, and wait for the worksheet change event to respond.

    In your next post, perhaps you can explain what you want instead of saying that my guesses aren't it.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Suspending a macro

    I don't want an InputBox cluttering up my spreadsheet.
    The only thing an inputbox can't ever do is cluttering up your spreadsheet. A user (or your VBA-code) can.

    Please Login or Register  to view this content.
    If you want to control both the user's input and your spreadsheet you'd better use a Userform.

  8. #8
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by shg View Post
    As is becoming apparent, I don't know what you're trying to do.

    You can select a cell, put a prompt in it, exit the sub, and wait for the worksheet change event to respond.

    In your next post, perhaps you can explain what you want instead of saying that my guesses aren't it.
    Sorry for any frustration/or controversy I might be causing. It is not intentional. I am writing a math trainer for my grandson and am in the earliest stages.

    The plan is to have two numbers generated randomly and displayed one above the other in a column. The student would then enter their answer in the cell below the question. Evaluation of the answer will generate a response ie. "Yes" or "No".

    Simple enough I know, however, I would prefer that the student not have to re-launch the macro after each entry or have to manually select the answer cell to respond to subsequent questions.

    I would like to evaluate the answer from within the macro, respond to it, generate new numbers and await a response. Hence my search for a method to suspend a macro, await input into a cell then resume the macro.

    My code so far is embarrasingly simple but I will post it if you think it will help. I would really like to learn more about the worksheet change event however.

    Thanks again

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    You don't need a macro for that.

    If A1 contains 3, A2 contains 4, and A3 is supposed to be the sum, then in A4,

    =if(a3="", "", if(a3=a1+a2, "Correct!", "Sorry , no!"))

  10. #10
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Thanks once again. I already have this solution implemented. If, however, I do learn how to suspend a macro, relinquish focus to the spreadsheet then resume after data input I will post it for all to see. I'am thinking that what I seek is not doable in VB.
    Last edited by shg; 08-15-2010 at 07:15 PM. Reason: deleted quote

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    As I said before, the macro can exit and wait for user input, as detected by the Worksheet Change event. See, for example, http://www.mvps.org/dmcritchie/excel/event.htm.

    Please post a link to other forums where you have posted the same question, and I strongly suggest you post a link in those other forums as well.

  12. #12
    Registered User
    Join Date
    07-22-2010
    Location
    USA
    MS-Off Ver
    2010
    Posts
    24

    Re: Suspending a macro

    Quote Originally Posted by OldTim View Post
    Thanks once again. I already have this solution implemented. If, however, I do learn how to suspend a macro, relinquish focus to the spreadsheet then resume after data input I will post it for all to see. I'am thinking that what I seek is not doable in VB.
    Explore this code attached. Not finished but should give you ideas. Pay attention to the code on sheet1.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    07-21-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Suspending a macro

    OldTim,

    This seems like a simple mathematical addition. Can you not have a "If" function in an adjacent cell (or any cell that can be seen when entering your answer) to display the response?

    e.g. If ( If A1 Or A2 = "", "", If ( A1 + A2 = A3, "Correct", Sorry, No") )

    Danny

  14. #14
    Registered User
    Join Date
    07-21-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Suspending a macro

    I boobooed on my "If" function. Here's the correct function.

    e.g. If ( A1 Or A2 = "", "", If ( A1 + A2 = A3, "Correct", Sorry, No") )

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    That's invalid syntax for what you're trying to do.

  16. #16
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by Cbrehm View Post
    Explore this code attached. Not finished but should give you ideas. Pay attention to the code on sheet1.
    Thanks. This has possibilities.

  17. #17
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by shg View Post
    As I said before, the macro can exit and wait for user input, as detected by the Worksheet Change event. See, for example, http://www.mvps.org/dmcritchie/excel/event.htm.

    Please post a link to other forums where you have posted the same question, and I strongly suggest you post a link in those other forums as well.
    I have only posted to one other forum. How do I post the links you urge?

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Suspending a macro

    Copy the URL for that thread from the browser address bar and post it here; copy the URL for this thread and post it there.

  19. #19
    Registered User
    Join Date
    08-15-2010
    Location
    Coquitlam, BC CA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Suspending a macro

    Quote Originally Posted by shg View Post
    Copy the URL for that thread from the browser address bar and post it here; copy the URL for this thread and post it there.
    I have terminated my post at excel help. I like it better here. Regards

  20. #20
    Registered User
    Join Date
    07-21-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Suspending a macro

    Thanks shg,

    What was I thinking?

    Proper syntax is "=IF(OR(A1="",A2=""),"",IF(A1+A2=A3,"Correct","Sorry, No"))"

    Another Homer Simpson moment.

    Danny

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1