+ Reply to Thread
Results 1 to 10 of 10

Exit Sub

  1. #1
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    890

    Exit Sub

    Afternoon,

    Would anyone be able to tell me why the following does not work?

    Please Login or Register  to view this content.
    In cell R3 i have the formula that will show X if a condition is met, or stay blank if condition is not met.
    So i was expecting the macro to stop running if R3 contained an X, but it does not, it instead continues onto the macro 'Arrive'

    Any thoughts please

    regards

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Exit Sub

    Hi,

    Try
    If Range("R3") = "X" Then
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-19-2012
    Location
    Wilmington Delaware
    MS-Off Ver
    Excel 2003 2007 2010
    Posts
    23

    Re: Exit Sub

    As it is a text comparison, try

    Please Login or Register  to view this content.
    Robert Flanagan
    http://www.add-ins.com
    Productivity add-ins and downloadable books on VB macros for Excel

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,525

    Re: Exit Sub

    You have not included the "equal to" condition. Your condition is "greater than (but not equal to) X" Try replacing the > with >= or =.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Exit Sub

    What is "x" ?
    Your condition is asking if A3 is greater than the letter x.

  6. #6
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    890

    Re: Exit Sub

    HAHAHAHA
    increcible.
    The minute you highlighted i had > instead of =, it made instant sense, and, actually works. (how embarrassing lol)

    OK, so in addition to this, i would like my VBA to do one of 2 things.

    1) If the cell R3 contains "X" then run macro "First"
    2) If the cell R3 conatins "X" then run the macro "Second" instead.

    Many thanks!

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Exit Sub

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-19-2012
    Location
    Wilmington Delaware
    MS-Off Ver
    Excel 2003 2007 2010
    Posts
    23

    Re: Exit Sub

    Your request was a bit confusing . Did you want it to run two macros if it contains X or run macro1 if it does and macro2 if it does not?

    Please Login or Register  to view this content.
    Robert Flanagan
    http://www.add-ins.com
    Productivity add-ins and downloadable books on VB macros for Excel

  9. #9
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    890

    Re: Exit Sub

    Sorry, i was typing in a rush, it should have said;

    1) If the cell R3 contains "X" then run macro "First"
    2) If the cell R3 does not conatin "X" then run the macro "Second" instead.

    But thank-you for the suggestions, i will try them all and feedback!
    regards

  10. #10
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    890

    Re: Exit Sub

    Fantastic!!
    i have amended my code
    Please Login or Register  to view this content.
    Which appears to run very nicely, thankyou to all for helping, rep added all round :D

+ Reply to Thread

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