+ Reply to Thread
Results 1 to 20 of 20

Suspending a macro

Hybrid View

  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...

    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        Answer = Range("G22").Value
        Range("G22").Select
        If Answer <> "" Then
            If Answer = MyTotal Then
                Range("G18").Value = "GREAT JOB"
            Else
                Range("G18").Value = "SORRY, TRY AGAIN"
                Application.EnableEvents = True
                Exit Sub
             End If
         End If
         MyTotal = 0
         For Each c In Worksheets("Sheet1").Range("G20:G21")
            MyValue = Int((15 * Rnd) + 1)   ' Generate random values between 1 and 15
            c.Value = MyValue
            MyTotal = MyTotal + MyValue
        Next c
        Worksheets("Sheet1").Range("G22").ClearContents
         Application.EnableEvents = True
    End Sub
    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
    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

  8. #8
    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") )

  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

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

  10. #10
    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