Results 1 to 4 of 4

MsgBox, vbNo problem

Threaded View

  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:

    If Ans = vbNo Then Exit Sub
    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:

    Config = vbYesNo + vbQuestion + vbDefaultButton2
    Ans = MsgBox("Sheet already exists. Do you want to delete?", Config)
    If Ans = vbYes Then
    Sheets(sProsp).Delete
    GoTo SheetNotFound
    If Ans = vbNo Then
    GoTo TheEnd
    End If
    End If
    Last edited by Carlsbergen; 08-30-2010 at 07:55 AM.

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