+ Reply to Thread
Results 1 to 4 of 4

MsgBox, vbNo problem

  1. #1
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    85

    MsgBox, vbNo problem

    Hey guys.

    Im having some problem with a simpe yes/no msgbox.
    I have a macro that creates a new sheet whose name depends on some value.
    I have created this little thing that checks if a sheet with the same name exists and
    if so then a msgbox will show where the user can choose to delete the existing sheet.

    If the user selects yes, the code works just fine.
    The sheet is deleted and jumps to the point SheetNotFound where the macro
    continues like normal.
    The problem happens when the user presses No.
    What I want to happen is that the macro should just stop.
    I have tried this:

    Please Login or Register  to view this content.
    Didnt work.


    So I tried to have it jump to the last line of the macro before End Sub but it doesnt
    jump there, instead it just continues down the macro until it crashes due to the fact that it tries to make a sheet with duplicate name.

    Here is my code:

    Please Login or Register  to view this content.
    Last edited by Carlsbergen; 08-30-2010 at 07:55 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: MsgBox, vbNo problem

    Your nesting of the IF statements is not right. Look up the IF - ElseIf syntax in the Excel VBA Help files.

    try

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-12-2009
    Location
    Udevalla, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: MsgBox, vbNo problem

    Thats works! Thanks!

    Weird..
    I got that code from the Excel 2003 Bible..
    Must be a typo or something.
    Last edited by teylyn; 08-30-2010 at 08:16 AM. Reason: removed spurious quote

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: MsgBox, vbNo problem

    If my suggestion beats an "Excel 2003 Bible" code, that's surely down to bad proof-reading rather than anything else.

    Please mark the thread as solved, if you feel your problem has been addressed in a satisfactory way.

    cheers, teylyn


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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