+ Reply to Thread
Results 1 to 27 of 27

Matching multiple times WITHOUT array formulas.

  1. #1
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Matching multiple times WITHOUT array formulas.

    Is this possible? To match multiple times, without the use of an array formula.

    So I was thinking it was, but got stuck on trying to "force" it to find the second, third, etc. matches. Everything I've seen uses array formulas, is that the only option?

    Could I do a separate formula for each "level" of match, for example a simple index(match() for the first match, then whatever for the second, etc.

    The reason I am asking this is because array formula are just causing problems with how I wanted to use them for my sheet. I wanted to be able to export my data (some 20,000 lines of data, varying length) into a tab, and have the formula do everything. Array formula work, but they take some tweaking to make it work.

    Thanks in advance if this is actually possible.

    I found http://dailydoseofexcel.com/archives...3rd-4th-match/ which suggests this is possible, but I couldn't really wrap my head around what they were doing.

    Criteria 1st Match 2nd Match 3rd Match 4th Match

    Is the format I am thinking of.
    Last edited by TheN; 08-12-2016 at 09:01 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Matching multiple times WITHOUT array formulas.

    What I have done before is to use a helper column with countif to ID the duplicates, then do the extract bases on that
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    There are two other ways that I can think of - the first would use a helper column to identify matches and allocate a unique sequential number to each match, and the second would be to adjust the range after each match and use INDIRECT (although that is a volatile function and could cause performance problems).

    Hope this helps.

    Pete

  4. #4
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    See the attachment.

    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by Pete_UK View Post
    the first would use a helper column to identify matches and allocate a unique sequential number to each match
    That probably sounds like the best bet for what I want, if I am understanding you correctly, anyway.

    Just to explain it a little better, I want to match multiple things at once, and have multiple outputs for each initial criteria. So I would want to store which match it is in the helper column, then use an if statement to pull the correct match for the column?

    So, for example:

    Category Output Helper
    Dog Affenpinscher 1
    Dog Airedale Terrier 2
    Cat
    Dog Alaskan Malamute 3
    Cat
    Cat
    Dog American Cocker Spaniel 4
    Cat
    Dog Beagle 5

    Yields:

    Category 1 2 3 4
    Dog Affenpinscher Airedale Terrier Alaskan Malamute American Cocker Spaniel
    Cat

    So, the helper column would basically do all the work.

    Let's say the formula for Helper column is:

    Please Login or Register  to view this content.
    Just so I can reference it, I'm not sure what the logic for it would be.

    Then we just use something like:

    Please Login or Register  to view this content.
    In cell B2 on sheet 2 and drag it down/right to get the desired results.

    I just need some help actually making the logic work. Really like that idea.

    I believe I understand how to come about a solution now, but actually coding the logic, is tricky. I'll have to think about it for a while, hopefully someone else comes up with a solution before me. So once again, I am stuck where I was stuck before, but at least I can picture the logic working in my head now, just need to come up with formulas to make it work.

    Last edited by TheN; 08-12-2016 at 08:43 PM. Reason: Example formula

  6. #6
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Did you see my attachment on Post#4? This is with that helper column.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    If in your lower table you only wanted to select one category (e.g. it could be a worker's name, so you only wanted the details for one person at a time) then the approach that you outlined would be fine - the helper column identifies only those records that match the criteria and allocates a sequential number. You could do that using this formula in C2:

    =IF(A2=$A$15,MAX(C$1:C1)+1,"")

    then copy that down. I'm assuming that A15 contains "Dog", and you might have a drop-down in there that allows you to select "Cat" instead. You would then have this formula in B15:

    =IFERROR(INDEX(B$1:B$10,MATCH(COLUMNS($B:B),$C$1:$C$10,0)),"")

    which you can then copy across. You could replace the COLUMN($B:B) term with B14 in this case, although you may not always have those numbers handy.

    However, if you want to have two or more items shown in the lower table, then the helper column needs to include something else to help identify the type of record, as well as the unique number. In this case I would use this in C2:

    =A2&"_"&COUNTIF(A$2:A2,A2)

    and copy down, and this formula would give Dog_1, Dog_2, Cat_1, Dog_3, and so on. Then in B15 you would have this:

    =IFERROR(INDEX($B$1:$B$10,MATCH($A15&"_"&COLUMNS($B:B),$C$1:$C$10,0)),"")

    which can be copied across AND down to complete the lower table.

    As you say, it is the helper column that does all the work, and the expressions in there can become quite complex - you might want to compare several columns of data, for example, so you would have an AND function - the crucial thing is that you are setting up some unique reference for each record, and then in your summary table you need to re-create those unique references in the MATCH function.

    Hope this helps.

    Pete
    Last edited by Pete_UK; 08-12-2016 at 09:11 PM. Reason: Corrected formula

  8. #8
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Also you can use another helper method. See this attachment.
    Attached Files Attached Files

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by sanram View Post
    Also you can use another helper method. See this attachment.
    Instead of hiding your suggestion in a file why don't you put it directly in the post where we can see it?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  10. #10
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by Tony Valko View Post
    Instead of hiding your suggestion in a file why don't you put it directly in the post where we can see it?
    Because this help people to understand well.

    On helper column I used that formula
    Please Login or Register  to view this content.
    On the output I used that formula
    Please Login or Register  to view this content.
    But they will make complete sense if you see the file I think. May be I think wrong.

  11. #11
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by Pete_UK View Post
    However, if you want to have two or more items shown in the lower table, then the helper column needs to include something else to help identify the type of record, as well as the unique number. In this case I would use this in C2:

    =A2&"_"&COUNTIF(A$2:A2,A2)

    and copy down, and this formula would give Dog_1, Dog_2, Cat_1, Dog_3, and so on. Then in B15 you would have this:

    =INDEX($B$1:$B$10,MATCH($A15&"_"&COLUMNS($B:B),$C$1:$C$10,0)),"")

    which can be copied across AND down to complete the lower table.

    As you say, it is the helper column that does all the work, and the expressions in there can become quite complex - you might want to compare several columns of data, for example, so you would have an AND function - the crucial thing is that you are setting up some unique reference for each record, and then in your summary table you need to re-create those unique references in the MATCH function.

    Hope this helps.

    Pete
    Awesome, that's basically what I was thinking, but I was trying to go about it wrong. You make things look so easy. However, I think you forgot the IF part of this formula:

    =INDEX($B$1:$B$10,MATCH($A15&"_"&COLUMNS($B:B),$C$1:$C$10,0)),"")

    I believe I know where you were going with it, but I'd still like to see if your thought process is easier than mine.

  12. #12
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Here my helper column is C.

    Column F contains all ID's from row 5. Row 5 contains matched number from column G to J.

    Then I used the following formula in G5 and copy them to other output cells.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by sanram View Post
    Because this help people to understand well.

    On helper column I used that formula
    Please Login or Register  to view this content.
    On the output I used that formula
    Please Login or Register  to view this content.
    But they will make complete sense if you see the file I think. May be I think wrong.
    Nope, your file accomplishes the same thing I wanted now. I didn't quite understand the first one, but this one makes more sense to me.

    Thanks to both of you, been a great help, I can tweak these to work with my real file now, thanks.

  14. #14
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Great! It sounds good now that you got the solution.

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    I've attached the file based on the second set of formulae that I gave you.

    Hope this helps.

    Pete

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    Sorry, forgot to attach it.

    Pete

    EDIT: And yes, I forgot the IFERROR in the earlier post (corrected now).
    Attached Files Attached Files

  17. #17
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by Pete_UK View Post
    Sorry, forgot to attach it.

    Pete

    EDIT: And yes, I forgot the IFERROR in the earlier post (corrected now).
    That's really a good solution by using columns().

  18. #18
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Matching multiple times WITHOUT array formulas.

    ah iferror(), I always forget about that one and go for if or if(iserror()).

    Thanks.

  19. #19
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by sanram View Post
    Also you can use another helper method. See this attachment.
    Sorry for off-topic interjection:

    Although there is no official rule regarding this behavior, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.

    I'm sure you understand, and we look forward to seeing you post your formulas/macros in your posts for the searching benefit of all.

    Thanks again for all your hard work here!

  20. #20
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by FDibbins View Post
    Sorry for off-topic interjection:

    Although there is no official rule regarding this behavior, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.

    I'm sure you understand, and we look forward to seeing you post your formulas/macros in your posts for the searching benefit of all.

    Thanks again for all your hard work here!
    Yes. I understand and always try to give my solution directly here. But sometime I couldn't express myself without a sample.

  21. #21
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    Just for completeness, I've put a file together to show how you can use INDIRECT to get multiple matches. This approach does not need a helper column, so I just have the same data as before in A1:B10, with "Dog" in A15. This formula in B15 will get the first record that matches:

    =IFERROR(INDEX($B$2:$B$10,MATCH($A15,$A$2:$A$10,0)),"")

    and it can be copied down for the other categories, but it can't be copied across as it will always return the first match. Instead, I've used this formula in C15:

    =IFERROR(INDEX(INDIRECT("B"&MATCH(B15,$B$1:$B$10,0)+1&":B10"),MATCH($A15,INDIRECT("A"&MATCH(B15,$B$1:$B$10,0)+1&":A10"),0)),"")

    and this CAN be copied across and down to pick up the subsequent matching records. It works by adjusting the ranges that are being searched, so as to exclude the rows where we have already found a match.

    Hope this helps.

    Pete
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    06-28-2016
    Location
    Pennsylvania, USA
    MS-Off Ver
    2013
    Posts
    308

    Re: Matching multiple times WITHOUT array formulas.

    Cool, never knew that was even possible.

    I'll stick to the helper column method, as it makes more sense to me, but that is quite the impressive formula there.

  23. #23
    Registered User
    Join Date
    12-11-2018
    Location
    Australia
    MS-Off Ver
    2012
    Posts
    3

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by Pete_UK View Post
    Just for completeness, I've put a file together to show how you can use INDIRECT to get multiple matches. This approach does not need a helper column, so I just have the same data as before in A1:B10, with "Dog" in A15. This formula in B15 will get the first record that matches:

    =IFERROR(INDEX($B$2:$B$10,MATCH($A15,$A$2:$A$10,0)),"")

    and it can be copied down for the other categories, but it can't be copied across as it will always return the first match. Instead, I've used this formula in C15:

    =IFERROR(INDEX(INDIRECT("B"&MATCH(B15,$B$1:$B$10,0)+1&":B10"),MATCH($A15,INDIRECT("A"&MATCH(B15,$B$1:$B$10,0)+1&":A10"),0)),"")

    and this CAN be copied across and down to pick up the subsequent matching records. It works by adjusting the ranges that are being searched, so as to exclude the rows where we have already found a match.

    Hope this helps.

    Pete
    This is a great method, however how can this apply across multiple worksheets (for external data source)? I've tried this, but it doesn't seem to cross reference correctly:

    =IFERROR(INDEX(INDIRECT("'new.xls'!B"&MATCH(B15,'new.xls'!$B$1:$B$10,0)+1&":B10"),MATCH($A15,INDIRECT("'new.xls'!A"&MATCH(B15,'new.xls'!$B$1:$B$10,0)+1&":A10"),0)),"")

  24. #24
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Matching multiple times WITHOUT array formulas.

    q_lander welcome to the forum

    Unfortunately your post does not comply with Rule 4 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

  25. #25
    Registered User
    Join Date
    01-13-2020
    Location
    Brussels, Belgium
    MS-Off Ver
    Office365
    Posts
    14

    Re: Matching multiple times WITHOUT array formulas.

    Hi Pete_UK,
    It is a great formula and i was going to use it in my document but unfortunally i run up to a problem. The formula can't handle 2 times the same output. For example, if there are 2 same dogs, the results after this for all other dogs become all the same.. That was a disapointment. Any way to solve this?

  26. #26
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,819

    Re: Matching multiple times WITHOUT array formulas.

    You should not try to hijack someone else's thread (see the Forum Rules at the top of the screen). Start your own new thread, with a link back to this if you think it is relevant.

    Pete

  27. #27
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Matching multiple times WITHOUT array formulas.

    Quote Originally Posted by VeKa27 View Post
    Hi Pete_UK,
    It is a great formula and i was going to use it in my document but unfortunally i run up to a problem. The formula can't handle 2 times the same output. For example, if there are 2 same dogs, the results after this for all other dogs become all the same.. That was a disapointment. Any way to solve this?
    Perhaps you missed my post IMMEDIATELY above yours regarding NOT posting questions in another member's thread?

+ 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] Find specific value in array which appears multiple times and average all relative cells
    By nenadmail in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-24-2014, 04:18 PM
  2. [SOLVED] two-array matching formula with multiple matches
    By ilikeexcel in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-09-2013, 02:19 PM
  3. Replies: 4
    Last Post: 01-18-2012, 09:55 PM
  4. =Lookup(Multiple names in a array) return the number of hours between 2 times
    By Nazerith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2011, 08:29 PM
  5. Matching on multiple columns array?
    By vertigo44 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2011, 07:46 AM
  6. SUMIF or an array formula - matching multiple conditions
    By Jason_2112 in forum Excel General
    Replies: 2
    Last Post: 01-14-2009, 06:03 PM
  7. Matching a value that appears multiple times
    By BKGT in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-27-2006, 11:40 AM
  8. Replies: 2
    Last Post: 01-12-2006, 12:25 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