+ Reply to Thread
Results 1 to 4 of 4

return row for nth occurrence of text in array

Hybrid View

  1. #1
    Registered User
    Join Date
    08-21-2010
    Location
    Omaha, NE
    MS-Off Ver
    Excel 2003
    Posts
    45

    return row for nth occurrence of text in array

    <SOLVED>

    Hello,

    I'll appreciate any help received. I've attached a small Excel 2007 document to demonstrate what I am trying to do and to provide data to ground a discussion.

    I'd like to sort column A and return the row number for the first occurrence of the letter 'a' formulaically (B1). In B2 second cell, I'd like to return the row number for the second occurrence of 'a', and so forth.

    So far I have not come up with a satisfying way of doing this and have not been able to find a post that has accomplished it. I've managed to do everything else without VBA so far, and would like to keep it that way if possible. I've tried combinations of Row(), Match(), Vlookup(), Countif(), and Indirect().

    Thanks!


    Greg
    Attached Files Attached Files
    Last edited by Greg777; 11-08-2010 at 07:04 PM. Reason: SOLVED

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: return row for nth occurrence of text in array

    in b1
    =MATCH("a",A1:A15,0)
    in b2
    =MATCH("A",INDIRECT("A"&B1+1&":a15"),0)+B1
    drag down to b3 for 3rd a and so on
    Attached Files Attached Files
    Last edited by martindwilson; 11-02-2010 at 08:34 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,698

    Re: return row for nth occurrence of text in array

    You mention sorting column A? this formula will work sorted or not to give successive instances, in B1

    =SMALL(IF(A1:A100="a",ROW(A1:A100)),ROWS(B$1:B1))

    confirmed with CTRL+SHIFT+ENTER

    when instances are exhausted you get #NUM! error....you could revise the formula to prevent that if you want....

    of course if the data is sorted the second occurence will just be 1 after the first and the third will be 1 after that etc......
    Audere est facere

  4. #4
    Registered User
    Join Date
    08-21-2010
    Location
    Omaha, NE
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: return row for nth occurrence of text in array

    These replies are fantastic. Thanks martindwilson and daddylonglegs. It was the tricky "A"&B1+1 segment that I had overcomplicated. I'll mark the post solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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