+ Reply to Thread
Results 1 to 9 of 9

How to exit a loop once the value is found in the range

  1. #1
    Registered User
    Join Date
    11-14-2008
    Location
    Saint Lucia
    Posts
    14

    Exclamation How to exit a loop once the value is found in the range

    Hi Guys,

    The following vba code runs when the user clicks the command button. It first calculates the CurrentWk and then searches the range c for the resulting value. I want the macro to run through each cell in the range c and exit the loop once c.value = CurrentWk.

    Can anyone assist?

    Please Login or Register  to view this content.
    Last edited by Suety; 09-28-2010 at 01:29 PM. Reason: Question answered

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: How to exit a loop once the value is found in the range

    Simplify
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: How to exit a loop once the value is found in the range

    Or do it properly, without the need to select random stuff...

    Please Login or Register  to view this content.
    Avoids the need to loop altogether.

  4. #4
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: How to exit a loop once the value is found in the range

    Quote Originally Posted by Andrew-R View Post
    Or do it properly, without the need to select random stuff...

    Please Login or Register  to view this content.
    Avoids the need to loop altogether.
    And a lovely solution 'tis!

  5. #5
    Registered User
    Join Date
    11-14-2008
    Location
    Saint Lucia
    Posts
    14

    Re: How to exit a loop once the value is found in the range

    Thanks guys for the suggestions! They both solved my problem...

    I have another question. In my code, if c.value = CurrentWk, i want it to select c and select 15 rows going down. how do i do this?

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: How to exit a loop once the value is found in the range

    Liking Andrew's solution better, I would do

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-14-2008
    Location
    Saint Lucia
    Posts
    14

    Re: How to exit a loop once the value is found in the range

    Thanks Blane! i used this suggestion... i forgot to mention something in my previous post.. i need to select 15 rows down and column A:AS across.

  8. #8
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: How to exit a loop once the value is found in the range

    You can the offset parameters accordingly.

  9. #9
    Registered User
    Join Date
    11-14-2008
    Location
    Saint Lucia
    Posts
    14

    Re: How to exit a loop once the value is found in the range

    thanks guys for all your help! it was much appreciated...

+ 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