+ Reply to Thread
Results 1 to 4 of 4

yes, no prompting user to rerun macro once macro has come to end (before END SUB)

Hybrid View

  1. #1
    Registered User
    Join Date
    01-05-2012
    Location
    Salinas
    MS-Off Ver
    Excel 2007
    Posts
    22

    yes, no prompting user to rerun macro once macro has come to end (before END SUB)

    Howdy again - appreciate all your help! I have a macro that takes data and then reformats it. Macro works great - at the end of it I would like to prompt the user (via Yes/No) whether they want to format additional data or end the macro. A "no" response would "END SUB" a "yes" response would take the user back to a certain pt in the macro. Is this possible? If not taking the user back to the beginning and rerunning the whole macro would be a second choice.

    How would you do this?

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: yes, no prompting user to rerun macro once macro has come to end (before END SUB)

    Something like this before the end of your macro:
        If MsgBox("Rerun Macro ?", vbYesNo) = vbYes Then
            'your code to rerun your macro here or insert a GoTo
        End If

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: yes, no prompting user to rerun macro once macro has come to end (before END SUB)

    Hi

    I'd go another way and have a controlling macro and the secondary macro that does your action. Something like

    Sub aaa()
      Dim cntr As Long
      cntr = 0
      Do
        Call bbb(cntr)
        cntr = cntr + 1
      Loop Until MsgBox("do again", vbYesNo) = vbNo
      
    End Sub
    
    Sub bbb(cntr)
      If cntr = 0 Then
        MsgBox "Full action"
      End If
      MsgBox "second part"
    End Sub
    With this structure, the first run through the entire sub runs, but for any subsequent runs, it only runs from the particular spot.

    HTH

    rylo
    Last edited by rylo; 10-03-2012 at 07:01 PM.

  4. #4
    Registered User
    Join Date
    01-05-2012
    Location
    Salinas
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: yes, no prompting user to rerun macro once macro has come to end (before END SUB)

    Thanks so much! This forum is awesome. Appreciate your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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