vbYesNo responses

  • I am calling a vbYesNo message box.


    If the response is Yes, the rest of the module runs as it should. That is what I want to happen on a Yes response.


    I would like a No repsonse to exit the Sub, but at the moment, when either Yes or No is clicked, the rest of the module runs.


    How do I get A No response to Exit Sub?


    Code
    Select Case Range("m52")
        Case 1
            If MsgBox("YOU HAVE BLANK FIELDS. DO YOU WISH TO CONTINUE", vbYesNo, "BLANK FIELDS") = vbYes Then
            End If


    Regards

  • Re: vbYesNo responses


    Hi reddale,


    This line of code will make it so that the macro will only continue if the user clicks Yes:


    Code
    If MsgBox("YOU HAVE BLANK FIELDS. DO YOU WISH TO CONTINUE", vbYesNo, "BLANK FIELDS") = vbNo Then Exit Sub


    HTH


    Robert

  • Re: vbYesNo responses


    Thanks Robert. Your line of code stops rest of the code from running when you click no, but when I click Yes, nothing happens. There is a fair bit of code after what we are talking about. The rest of the code doesn't run. If it makes a difference, I am calling this message box via Case Select


    Any suggestions?

  • Re: vbYesNo responses


    Quote

    Your line of code stops rest of the code from running when you click no


    Correct - isn't that what you wanted :confused:


    Quote

    but when I click Yes, nothing happens


    That's nothing to do with the code I gave?? If the user clicks Yes your code will continue as it is. I can't comment without seeing the whole code but if it's as big as you suggest I probably won't be able to offer much help.


    Try stepping through the code via pressing F8 to see what's happening.


    Robert

  • Re: vbYesNo responses


    Robert


    I'm not sure what is going on. When I comment out your code (and mine when I put it back in for a test) the rest of my code works fine.


    When No is clicked in the message box, it stops the code like I require, but in your code or mine, clicking Yes does the same thing. The rest of the code doesn't run.


    I stepped through all the code and didn't get any clues at to why Yes stops the code, just like No does.


    Back to Google

  • Re: vbYesNo responses


    It might be because the rest of your code is not part of the Case. Had that a few times. Easier way would be to not use Case & just go with

    Code
    If MsgBox("YOU HAVE BLANK FIELDS. DO YOU WISH TO CONTINUE", vbYesNo, "BLANK FIELDS") = vbNo Then
        Exit Sub
    Else
        'Rest of Code
    End If

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!