I'm trying to tweak this piece of code I found in a sample spreadsheet online but I can't quite get my head around it.
The original spreadsheet basically does an INDEX/MATCH based on a user-defined lookup and lists the matches neatly in a concatenated list. The sample spreadsheet's output looks like this:
http://i.stack.imgur.com/DyahB.png - Sample Excel Output (Note how there are no gaps between the first and second matches)
The underlying algorithm is:
=IF(ISERROR(INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2)),"",INDEX($A$1:$B$8,SMALL(IF($A$1:$A$8=$E$1,ROW($A$1:$A$8)),ROW(1:1)),2))
Now, I want the lookup to instead retrieve PARTIAL matches, and in addition, generate the outputs horizontally like so:
http://i.stack.imgur.com/ShED0.png - Output is generated horizontally based on partial matches
I'm not sure how I would go about doing this. It seems like I would somehow try and change the IF condition to return true on partial matches but I can't get my head around it. Please help!
Assuming by "partial match" you mean text that starts with the value in L1 then use this formula in N1
=IFERROR(INDEX($I$2:$I$8,SMALL(IF(LEFT($H$2:$H$8,LEN($L$1))=$L$1,ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")
confirm with CTRL+SHIFT+ENTER
and copy across
For a match anywhere in the text you can use this version
=IFERROR(INDEX($I$2:$I$8,SMALL(IF(ISNUMBER(SEARCH($L$1,$H$2:$H$8)),ROW($I$2:$I$8)-ROW($I$2)+1),COLUMNS($N1:N1))),"")
Neither formula is case-sensitive, although you can easily make the latter so by changing SEARCH to FIND
Use of IFERROR function means you don't need repetition for error handling - needs Excel 2007 or later version
Building on Barry's code a little, I needed to make a few tweaks for my own use (current project I have at work).
Tweaks I made:
Returning the cell that matches my search criteria in my index
Making the cell draggable in two dimensions so I could index multiple columns for specific information
Making the "nth" counter vertical instead of horizontal (as my application is a database of sorts, and each column is a separate entry. At the top of each column is 5 rows populated based on the search term [in my case, the store number])
The final result is:
=IFERROR(INDEX(A$8:A$295,SMALL(IF(ISNUMBER(SEARCH('Store History'!$F$2,A$8:A$295)),ROW(A$8:A$295)-ROW(A$8)+1),ROWS(A$2:A2))),"")
It is worth repeating that this is an array formula and needs to be entered using CTRL+SHIFT+ENTER
This is placed in cell A2 and is dragged both vertically and horizontally (horizontally in my case is ever expanding as I add more entries into my database).
My purpose for adding this comment (even though it is a long inactive thread) is to try and make this a more relevant search result on Google for "excel index match partial strings with multiple results" or variations of that. It took me hours of searching to find this solution, and it is extremely functional and elegant. My thanks to the OP and especially to Barry for his code!!
Related
I have two columns of words (Old list) and (New list)
I'm trying to check using the VLOOKUP() function both columns and find which words of the New list doesn't appear in the Old list.
(The answers here is obviously: eyes, john, martha, phone)
I'm giving this simple example to know what VLOOKUP() formula to also apply to a larger sample. In reality I have two columns of over 1000 items. Thanks
=FILTER(F2:F10, ISNA(VLOOKUP(F2:F10,A2:A10,1,FALSE)))
This will filter it down and remove all the N/A values while comparing the 2nd list to the first.
EDIT:
as per comment needing clarification (too long to put as a comment)
You can do anything you’d like by substituting references. It’s best to think of the syntax of things here to get a lay of the land and figure out what you want to pull information from.
The ISNA() just handles N/A errors that will occur with partial lists and is irrelevant to understanding where to put your references.
=filter(array, include, [if_empty])
Where “array” is the range you want to filter FROM
And “include” is what you are searching FOR from that range.
The [if_empty] is optional – you can put a text there, like “No Results” in quotes so that it’ll substitute that for N/A.
The “include” portion is where I’ve added additional information because I want to narrow in what I’m including…. In the plain and simple form of =filter() you’d just be putting a word/cell reference you’re looking for. It’ll pull every column for the whole table if there are multiple columns. But we want it to search multiple criteria simultaneously.
=vlookup(lookup_value, table_array, col_index_num,range_lookup)
what you are searching FOR (in this case anything within the table), where you want to look for it (where you are searching FROM), which column to find it in (column 1 in your case), and TRUE/FALSE – exact or approximate matches.
The easiest way to search across multiple sheets is to have the files open, and as you type in the formula bar when you get to each section click and highlight what you want by switching sheets (alt tab). Just pay really close attention to searching FOR versus searching FROM and you can do any combination of comparison you need.
If you would like TRUE/FALSE for each element you can use the following
=ISNUMBER(MATCH(A1,ColumnToSearch,0))
I have a large-ish spreadsheet of about 1400 rows. One of the columns in that row has been populated from a free-flow text and contains details about numerous items people are requesting. There's no consistency about what's in the text box though.
Image 1 has an example of what the data looks like. C2 is the cell with the data in is. D2 is where I want to extract the list of things from C2 to. If an item appears multiple times I only want it to show once.
Example image of data
The list where the things I want to look for is on a separate sheet (Example of list array) and the list is defined by the range name "items" and runs from A2:A95.
I'm using Excel365 (despite the example screenshots) and have been trying various solutions from here on SO and various other Excel help pages but can't find anything that will work how I've got things setup. I've nothing against using VBA if that's the only way to do it, but would prefer a simpler solution if possible.
Thanks in advance.
I created a Named Range for your reference list so in my formula ThingsToLookUp is referencing the range A2:A9 in my sample file below.
=TEXTJOIN(", ",TRUE,IF(ISERROR(SEARCH(ThingsToLookUp,C2)),"",ThingsToLookUp))
Note that you will stumble on some edge cases here with SEARCH. For instance, if the string has Crossbow you will always output Crossbow and Bow since the later is a substring of the first. Less important but this solution also outputs the items in the order as they appear on the reference list, not as they appear in the input string.
I've made a list of bars for my friends/coworkers and I want to add a tool that allows them to search for bars that match their preferred criteria.
The google sheet can be found here.
I want the user to be able to search based on the criteria they input on the left under "keywords". So this many be anywhere from 1, keyword to all 7 filled out. But I want it to search based on any combination.
I initially started with an INDEX/MATCH formula which only returned a single row.
I landed on the FILTER function after trying different options.
However, this does not ignore blank search terms. Cell D4 on the Search page has the current formula. This will filter by Area, and then Area and Category if both are filled out, but I have yet to figure out how to expand this to the remaining filters.
My current function is the following:
=IFERROR(IF(AND(LEN(B6),LEN(B7)),FILTER(AllInfo,Area=B6,Category=B7),FILTER(AllInfo,Area=B6)),"-")
The filter function does exactly what I want for one search criteria, but my attempts to include any combination of search terms have failed.
I have a number of named data ranges which reference their respective columns on the 'Toronto - BARS' sheet.
Feel free to share this list with any friends living in Toronto!
Edit: removed irrelevant information
The closest I got is the formula below, which requires you to replace the boolean values into "yes" and "no" (or any other string values):
=ArrayFormula(query({AllInfo},"select * "&if(counta(B6:B12)>0,"where ",)&join(" and ","Col"&(match(filter(A6:A12,B6:B12<>""), transpose('Toronto - BARS'!A1:I1),0))&"='"&filter(B6:B12, B6:B12<>"")&"'"),0))
2 improvements that could be made, but I didn't figure it out:
using the column names in the query, instead of column number
parsing the boolean values correctly and add or remove the single quotes accordingly, so it can support the current boolean values / checkboxes
==> I hope someone can pick that up and finish what I couldn't get done.
I'm trying to find a way to perform an INDEX MATCH lookup that goes beyond the first match to check if all matching values are equivalent. I've found formulas that will return all matches, but what I'd like to do is have the matching value returned in the formula cell, but only if all values returned are the same.
Here's an example:
I'm matching the report number with the report number below and only picking up the area value if all report-area combinations are the same. Is there a clean way to do this?
Dan.
My solution may seem a bit messy, but you can make it simpler as you go, once you start implementing it:
First, I made a Report Count. (How many 12345 Reports are there in total, and so on).
=COUNTIF($A$2:$A$10;A2)
Then, I concat the Report-Area to get a unique identifier for every Report-Area combination.
=A2&"-"&B2
Now, I make a Count of that column, meaning I count how many combinations are there for each case (e.g. how many 12345-2C are there in total).
=COUNTIF($D$2:$D$10;D2)
Then, I create an "Ok" Column for checking if the Report Count matches the Concat Count.
=IF(C2=E2;"OK";"")
That said, we have our table ready for checking what you're looking for.
In just one formula (the one under Lookup header) on cell B13:
=IF(INDEX(F2:F10;MATCH(A13;A2:A10;0))="OK";INDEX(B2:B10;MATCH(A13;A2:A10;0));"")
I check IF there's an "OK" on the OK column for that Report number.
If there is, I Search for the "Area" value for that Report number.
If there isn't an "OK", I leave a blank cell. (In your example, it's #N/A)
The formulas on H2, I2 and C13 are just for reference. Plain text.
Again, I know it seems messy, but if you're not too familiar with some Excel formulas and functions, this is a good way to learn and build complex formulas step by step (Just as our fellow n8 said)
I assume you understand how INDEX MATCH works. If you don't, I'll edit an explanation for you.
Good Luck!
This question will be almost exactly like the question below, but I need a slight change to it for my application and I can't quite figure it out:
excel: how can I identify rows containing text keywords taken from a list of keywords
If a row of several text filled cells contains any keyword from a list of keywords, I would like to add that keyword to the end of the row. Each row will be the same number of cells, but some can be blank and they are not necessarily all the same data type, some could be numbers or dates etc. Even more, I would like to add every keyword that appears in the row of text to the end of the row in separate cells.
Relating to the example post that almost answers my question, I am using the more complicated formula for multiple matches, but in that example they only have one column of data they are looking for keywords in. I have several that would be formatted similar to their column A. I tried changing some of the ranges around with no luck specifically where the formula posted has: IF(COUNTIF($A1,"*"&$B$1:$B$10&"*") I changed $A1, to $A1:$D1 with no luck.
The problem showed up because I have several large spreadsheets of text based data about failure modes of different tools and I would like to categorize them in a little more of a controlled way than free form text in every cell and assigning controlled keywords that apply seems like a decent way to do this.
Example case
Expected result
The keyword list shown in Example Case is not shown in the Expected result. The range of keywords is K2:K6
Another feature that would be useful is if I could assign additional words that when found would trigger one of the key words. For example if the key word is "Gear wear" then "Gear wear" would trigger a hit but "stripped gears" would also trigger a hit. I would imagine the keyword list would be set up as a 2D Range with the first column being the actual key word and the cells to the right of each row would be additional words that trigger the key word. I suspect I am getting to the point where I would need to create a VBA macro to do this. If there is a way to accomplish this without writing code it would make it more repeatable on other user's computers.
Enter following formula in Cell F1 then drag/copy across and down as required.
=IFERROR(INDEX($K$2:$K$6,SMALL(IF(COUNTIF($A1:$D1,"*"&$K$2:$K$6&"*"),ROW($K$2:$K$6)-ROW($A$1)),COLUMNS($A1:A1))),"")
This is an array formula so commit it by pressing Ctrl+Shift+Enter
See the image for reference
This formula is derived from the link mentioned in your question.