+ Reply to Thread
Results 1 to 5 of 5

Put Find code in Loop to find all matches

  1. #1
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    209

    Put Find code in Loop to find all matches

    hi guys,

    Is there a way to put the below in a loop so that it finds all of the matches, not just a single match then move onto the next Ccell.

    At the moment it is finding 'Sarah' (for example) and then copying the line then moving to 'Forum' when in fact there are multiple 'Sarah's, and I wanted all the Sarah's to be copied then for it to look for the next in the list (Forum).

    as a side note it would really really be appreciated if you can educate\talk me through the looping code that you come up with as I would love nothing more than learn in all honestly.

    Thanks a lot in advance,

    FYI: the below code works atm , just not how i would like it.

    Please Login or Register  to view this content.
    Last edited by SarahPintal; 02-08-2010 at 09:05 PM.

  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: Put Find code in Loop to find all matches

    I don't think you need a loop to find all the "Sarah" values in column A and copy the rows. You need to turn on the Data > Filter > Autofilter and filter column A by the name "Sarah". Then you can copy all visible rows to the other sheet, turn off the filter and you got them all.

    If you attached a sample workbook with this code with a good "sample results" page so we can see the before/after, we can help more accurately.
    _________________
    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
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    209

    Re: Put Find code in Loop to find all matches

    Thanks for your response,

    That is one way of doing it if there was only 1 item to find, though there may be 20 items to find (itam = a differnt name), hence why I thought a loop would be the best and some how setting a variable to the first cell address of the the item found.. then the code will loop through all of the range trying to find any other mathes of that item until it gets back to the first cell address..

    hope that made sense

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Put Find code in Loop to find all matches

    Maybe like this, Sarah.

    The variable sAddr caches the address of the first cell found containing each value. The inner loop iterates until it finds the same cell again. I didn't set up anything to test it with, so it's ... untested.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    209

    Re: Put Find code in Loop to find all matches

    Worked like a charm, Thanks shg,

    I was working on some code that was more or less like yours, but it kept on failing, I think i can see why (a few things).

    I am going to continue to compare what code i just did in the last 30 mins with your to keep learning..

    Thanks

+ 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