+ Reply to Thread
Results 1 to 6 of 6

Stopping a Loop in a macro when a keyword appears.

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2000
    Posts
    23

    Stopping a Loop in a macro when a keyword appears.

    Hi guys

    I have this bit of code on the end of a macro, to calculate a value and move on to the next line. When Cells(i, 1).Value have "(blank)" written in the cell, I want to stop the loop, how do I do that?

    Please Login or Register  to view this content.
    Don't think having the workbook is essential to solving this, but if it's required i'll upload it

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Stopping a Loop in a macro when a keyword appears.

    one way:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Stopping a Loop in a macro when a keyword appears.

    Try this untested

    Also modify I am not sure if you meant blank cell or string "(blank)"

    Please Login or Register  to view this content.
    Thanks

  4. #4
    Registered User
    Join Date
    07-30-2013
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2000
    Posts
    23

    Re: Stopping a Loop in a macro when a keyword appears.

    Thanks guys! I went for fredlo's one because I understood it better, (bit of a programming noob), thank you for the help!!

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Stopping a Loop in a macro when a keyword appears.

    You are welcome. This is the good part of VBA you can achieve same result using different methods. JBeaucaire used a different kind of loop.

    I am wondering if there is a significant speed or gain between one or the other JBeaucaire? you are the expert here.

    Thanks

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Stopping a Loop in a macro when a keyword appears.

    Nah, a loop is a loop in this scenario. I'm a fan of DO loops.

+ 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] Loop Not Stopping
    By Dummy99 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-17-2016, 03:58 PM
  2. I need help stopping a loop in excel macros
    By vpapolu24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2013, 04:44 AM
  3. Copy and Paste Loop but keeps stopping
    By kksf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2013, 04:03 AM
  4. Loop is stopping for no apparent reason.
    By Melissa9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 03:08 PM
  5. Stopping A Loop When A Blank Cell Is Reached
    By Aaron1978 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2006, 07:48 AM

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