+ Reply to Thread
Results 1 to 4 of 4

Stop Sub if Condition is True

  1. #1
    Registered User
    Join Date
    01-12-2020
    Location
    Philadelphia, PA
    MS-Off Ver
    2016
    Posts
    97

    Stop Sub if Condition is True

    I'm writing my first Macro that contains an IF statement, and after 15 minutes, I've decided to pop my head in and ask for help.

    I have a macro that already works the way I want it to. But now, I want to add a condition that has to be met before it runs.

    All I have so far is
    Please Login or Register  to view this content.
    I want it to then stop running if CF5=1. If CF5=0, I want it to keep going.

    I can't figure out the proper syntax. If I try putting "Stop" after the MSGBOX I get a message about an End of Statement. I've also tried using ELSE and ENDIF, but I'm getting an error saying there's no "IF".

    I need help! Thanks in advance!

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Stop Sub if Condition is True

    Not sure I've fully understood, but I'll guess at what you mean to get the ball rolling.

    Try this:

    Please Login or Register  to view this content.
    The Exit Sub may not be necessary if there's nothing after the IF statement, but to help there would require much more information from you on the project.

    Also worth noting, you rarely actually need .Value, the code would work just as well without it and saves a fair bit of typing on large projects!

    BSB
    Last edited by BadlySpelledBuoy; 07-04-2022 at 11:15 AM.

  3. #3
    Registered User
    Join Date
    01-12-2020
    Location
    Philadelphia, PA
    MS-Off Ver
    2016
    Posts
    97

    Re: Stop Sub if Condition is True

    Actually, that worked just fine. I put the first line in front of my macro, and the ret of it after. Thanks!

    Could you tell me in what way I was using "Stop" incorrectly?

    As for the "Value", thanks for the tip. I've learned all my VBA from Google on an as needed basis, so any shortcuts are appreciated!

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Stop Sub if Condition is True

    Wasn't a bad guess then

    Happy to help.

    Have fun with the learning. We're here to help!

    BSB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Stop if True Doesn't Stop if True
    By Cmil in forum Excel General
    Replies: 3
    Last Post: 03-25-2021, 08:46 AM
  2. Stop Condition if not true
    By Chantal4130 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-27-2017, 11:26 AM
  3. Help popup window if condition is TRUE in change event if conditon is true
    By fanku in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2014, 12:46 PM
  4. Stop if True does not work in conditional formatting
    By Faridwahidi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-17-2014, 12:07 PM
  5. open a comment to cell range upon true condition then removing comment on false condition
    By ferrum_equitis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2012, 12:55 AM
  6. [SOLVED] How do I stop Excel from changing the word true to TRUE?
    By Schmyerlou in forum Excel General
    Replies: 1
    Last Post: 11-23-2005, 05:00 PM

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