• Very easy question (Excel/VBA)

    Author
    Topic
    #360638

    Here’s a quick one I could use help with:

    How do you stop (cancel) a macro in an If….Then…Else statement?

    All I’m trying to do is say that IF the user clicks the No button, THEN stop the macro, ELSE, carry on running through the lines following after right down to the End Sub.

    Also, can anyone recommend any good sites for ‘VBA 101’ or similar? The sort of thing that will start with “This is how we tweak a message box” and “This is why we declare our variables”.

    Many thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #543503

      Have you tried this?

      IF ‘click on No button’
      THEN END SUB
      ELSE

      It sounds logical to me but i’m sort of new to VBA

    • #543508

      You can use this to exit the current sub:

      If endcondition then
      Exit Sub
      End If

      There is also the End statement, which stops execution immediately and therefore can make an almighty mess if you’re not careful to clean up before using it. In fact, best not to use it at all!

      BTW drkrealm has an excellent spreadsheet with links to all sorts of tutorials; I think he posted it recently.

      HTH

      graeme

      • #543514

        Thanks guys. Exit Sub was what I was looking for.

        See, easy isn’t it?

    Viewing 1 reply thread
    Reply To: Very easy question (Excel/VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: