Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Darkest Kent, UK., Kent, England
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Very easy question (Excel/VBA)

    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.

  2. #2
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    Kent, England
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Very easy question (Excel/VBA)

    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

  3. #3
    New Lounger
    Join Date
    Sep 2001
    Location
    Paignton, Devon, England
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Very easy question (Excel/VBA)

    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

  4. #4
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Darkest Kent, UK., Kent, England
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Very easy question (Excel/VBA)

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

    See, easy isn't it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •