Finding the index of a matching wildcard in excel - excel

Given a sheet like so:
Sheet 1
Product Name
-----------------
Fancy Shoes
Plain Shoes
Comfy Slippers
Nice Loafers
Pressed Shirt
Tee Shirt
Collared Button-Up
and a sheet of wildcards:
Sheet 2
Product Wildcard | Product Category
---------------------------------------
*Shirt | Shirt
*Button-Up | Shirt
*Shoes | Shoes
*Loafers | Shoes
*Slippers | Shoes
I'm hoping to produce the following:
Product Name | Product Category
----------------------------------------
Fancy Shoes | Shoes
Plain Shoes | Shoes
Comfy Slippers | Shoes
Nice Loafers | Shoes
Pressed Shirt | Shirt
Tee Shirt | Shirt
Collared Button-Up | Shirt
In other words, can I lookup a category for a product in Sheet 1 that matches a Product Wildcard in Sheet 2?
I've tried to use VLOOKUP('Sheet 1'!A2, 'Sheet 2'!A2:B6, 2, FALSE) and MATCH('Sheet 1'!A2, 'Sheet 2'!A2:A6, 0). Both give me #N/A. I suspect those functions expect the search text to be the only thing that can be wildcarded and my Product Wildcards are taken literally and not interpreted as wildcards.
I'm wondering if there is another way to do this with built-in Excel functions, or if I'm going to need to write some VBA?
Thanks in advance for help on this!

The below is an array formula (entered with Ctrl+Shift+Enter):
=INDEX(Sheet2!$B$1:$B$5,MATCH(1,MATCH(Sheet2!$A$1:$A$5,Sheet1!A1,0),0))
You can use "Formulas" > "Evaluate Formula" on the cell containing the formula to see how it's working step by step.

Based on my reading here (specifically the note at the bottom), this seems to not be possible using VLOOKUP alone. If all of your wildcards don't have spaces, you could do it like this: (not an explicit formula, just a list of algorithmic steps)
Reverse the string, with something like this (this is an array formula, so Ctrl+Shift+Enter is required to use it)
Use FIND to get the location of the first space in the reversed version, subtracting that from the LEN of the string gives you the amount of string before the wildcard bit.
Use RIGHT to truncate the string to the wildcard, and use that with VLOOKUP.

If there are only two words in each cell and the word that determines the category (ex.: Shoes, Slippers, Shirt, etc...) is always second, you can use the following INDEX/MATCH to get the category:
=INDEX('Sheet 2'!B$2:B$6,MATCH(MID('Sheet 1'!A2,FIND(" ",'Sheet 1'!A2)+1,LEN('Sheet 1'!A2)-FIND(" ",'Sheet 1'!A2)),'Sheet 2'!A$2:A$6,0))

Related

Alternate row colour by data in fields in a spreadsheet

Good Afternoon all,
I've had a search but can't find the answer - please direct me if there is one!
I'm looking to make my spreadsheet have better readability to the user. It requires a lot of manual work outside of the sheet, so the less time strain the spreadsheet is, the better.
I know to to use =mod() in Conditional Formatting but this isn't what I'm looking for
I also know about opening the filter drop down, and clicking one cell, pressing down twice and pressing space bar (rinse and repeat) - but I'm not going to do this over 1000 rows...
Is there a way to alternate the colours from a filtered name in excel?
For example:
+---------------+---------------+--------------+
| Site Code | Site Name | Changed Date |
+---------------+---------------+--------------+
| 000020 | Bobs site | 28/11/18 | <-- colour 1
| 000020 | Bobs site | 26/11/18 | <-- colour 1
| 059201 | Julian's | date | <-- colour 2
| 059201 | Julian's | date | <-- colour 2
| 002237 | etc. 1 | date | <-- colour 1
| 523878 | etc. 2 | date | <-- colour 2
| 523878 | etc. 3 | date | <-- colour 2
+---------------+---------------+--------------+
So rather than by line number, it would be by the name "bobs site" would be one colour, the next in the list would be another colour etc
I would love for this to apply to site code and site name, so when filtering by either, the rows are highlighted correctly.
I can't do this in the =mod() kind of way, as some sites have just one entry, most have 2 and a few can have up to 10
EDIT: Proof of the answer working for future references
Doable with a helper column and Conditional Formatting with COUNTIF and MOD.
In the helper column:
=OR(A2<>A1,B2<>B1)
which returns TRUE or FALSE if the site code or site name has changed (or not) compared to the previous row.
Then 2 conditional formatting rules:
=MOD(COUNTIF($D$2:$D2,TRUE),2)=0
=MOD(COUNTIF($D$2:$D2,TRUE),2)=1
The mixed reference ($D$2:$D2) in the COUNTIF will allow for each separate section to be coloured alternately as the instances of TRUE are successively added up.
One solution; get all uniq values in a seperate column, copy column you want to refer to, paste to new column, remove duplicates.
Then select area with data and start refering those values you want to have that color i conditional formatting.
Edit
With more options use "AND" or "OR"

Count or Sum (?) items in a single cell that match criteria from a list in Excel

I have a single cell that is the output of a survey, that contains items selected from a list of 20 possible items.
ie.
Original possible selections:
Ape, Blue, Cat, Red, Dog, Yellow, Pig, Purple, Zebra
User is asked to "select all of the animals," from the list of possible selections. The output places all of the items they've identified into a single cell, separated by commas.
A new row is created for each survey entry.
ie.
| User 1 | "Ape, Cat, Pig, Purple" |
| User 2 | "Cat, Red, Dog, Pig, Zebra" |
| User 3 | "Ape, Cat, Dog, Pig, Zebra" |
etc...
I have a table with all of the animals and colors, with defined ranges.
ie. animals = A1:A5, and colours = B1:B4
I need to "score" the cell for each user, in a new cell. Where the score value is the count of the number of correctly identified items each counts as 1 point.
ie.
| User 1 | "Ape, Cat, Pig, Purple" | 3 |
| User 2 | "Cat, Red, Dog, Pig, Zebra" | 4 |
| User 3 | "Ape, Cat, Dog, Pig, Zebra" | 5 |
What would the formula need to be for that score cell for each row?
I found a previous thread, that seems to point in the right direction,
Excel: Searching for multiple terms in a cell
But this only checks for the existence of any of the items in a cell from a list and returns a true or false
Thanks for anyone's help!
COUNTIF with SUMPRODUCT:
=SUMPRODUCT(COUNTIF(D2,"*" & $A$1:$A$5 & "*"))
Which also has the limitation of the amimals not being a sub-string, like Ant and Ant-Eater
If sub-strings are a problem then use this:
=SUMPRODUCT(--(ISNUMBER(SEARCH(", " & $A$1:$A$5 & ", ",", " & D2 & ", "))))
This will make a complete match between the commas.
The formula shown is entered in D3 (an array formula, so use Ctrl+Shift+Enter) and filled down to D5
A3:A6 is a named range "animals"
Note this is only reliable if none of your terms are sub-strings of another term.
If you do not like to use the formulas above, which are very efficient and most ideal, a simpler but longer way would be as follows:
select the animals--> Data--> Text to Columns, and split them into columns with the separator being a comma
Once this is done, do a countif on each column, and it will total it up for you. You will need to do 20 countifs though, so it is far from ideal
IE
=countifs(column which it could be in],[no.1 animal])+
countifs(column which it could be in],[no.2 animal])+...
countifs(column which it could be in],[no.20 animal])
This is easy to see how it works and if you receive more answers you will have to split them out again

Excel: Using find() when find value exists multiple times

I'm having difficulty using the find() function when in this situation. Say, I have a big text string called "Inventory", which might look like this:
"[some text] 25 Item ABC [more text]"
I want to build a sheet that turns this text string into a proper spreadsheet which looks like this:
|Item A | 0 |
|Item AB | 0 |
|Item ABC | 25|
I'm having some success using a combination of MID() and FIND() to pull out the numbers, using this formula:
=IFERROR(NUMBERVALUE(MID([text field],FIND([Item Name],[text field])-4,3)),0)
but I'm getting this instead:
|Item A | 25|
|Item AB | 25|
|Item ABC | 25|
This is because "Item A", when searching through the text field, finds "Item A" in "Item ABC". How do I isolate it out such that I'm only returning results for "Item ABC" rather than "Item A" and "Item B" as well?
Can you search for an item name with a space after it? ie search for "Item A " instead of "Item A". This relies on a space being used after every item name though.
You formula would become
=IFERROR(NUMBERVALUE(MID([text field],FIND(CONCATENATE([Item Name]," "),[text field])-4,3)),0)
I can't help until you clearly define the text string. I suspect it has characteristics that you could use.
Ideally it should have a delimiting character like a ; or , between ever number and name. Can you change it to have this? This would be the best idea then you can use the suggestion I made above but use ";" instead of " ".
The only other solution will get complicated - you'll need to search for text followed by "a space and one or more numbers". You won't be able to use find for this and would have to use VBA and you don;t want to go there.
First, using the find and left functions, drop off everything to the left of item, so your string now starts with "item" and is in a different column. Run Text to columns on that column that has the first result, delimiting by space (record a macro while you're doing it the first time to just run automatically in the future). End result will be the item numbers will be alone in one column.

I need help looking for a value and return value of cell to the right in excel

i am having a problem with the lookup function in excel. i need to look through a column and get a return value from data in the same row but column to the right.
ie
1 | bob |
3 | jim |
7 | lis |
i want to search for the value 1 then return the name bob
Thanks for the help!
=VLOOKUP(1,A:B,2,FALSE)
Go into help file and read about VLOOKUP for more details.
Rather than use vlookups, Index, Match is recommended. Here is a great explanation.
http://www.mbaexcel.com/excel/why-index-match-is-better-than-vlookup/
The formula to find the name associate with "1" becomes:
=INDEX(B:B,MATCH(1,A:A,0))

Match text from column within a certain cell - Excel

I have a column of few thousand filenames that are not uniform. For instance:
| Column A | Column B |
===============================
| junk_City1_abunc | City1 |
-------------------------------
| nunk_City1_blahb | City1 |
-------------------------------
| small=City2_jdjf | City2 |
-------------------------------
| mozrmcity3_somet | City3 |
I would like to identify the city within the text in column A and return it in Column B.
I've come up with a complex formula that does the trick, but it is difficult to adjust if more cities are added within the filenames in new entries within column A.
Here is an example:
=IF(ISNA(MATCH("*"&$W$3&"*",I248,0)),IF(ISNA(MATCH("*"&$W$4&"*",I248,0)),IF(ISNA(MATCH("*"&$W$5&"*",I248,0)),IF(ISNA(MATCH("*"&$W$6&"*",I248,0)),IF(ISNA(MATCH("*"&$W$7&"*",I248,0)),IF(ISNA(MATCH("*"&$W$8&"*",I248,0)),"Austin","Orlando"),"Las Vegas"),"Chicago"),"Boston"),"Las Angeles"),"National")
It seems like there should be an easier way to do it, but I just can't figure it out.
(To make matters worse, not only am I identifying a city within the filename, I'm looking for other attributes to populate other columns)
Can anyone help?
Use the formula =IFERROR(LOOKUP(1E+100,SEARCH($E$2:$E$11,A2),$E$2:$E$11),A2)
This does *****NOT***** have to be array entered.
Where $E$2:$E$11 is the list of names you want returned and A2 is the cell to test
If no matches are found instead of errors you will just use the full name in column b.
If you want errors or expect to NEVER have then you can just use:
=LOOKUP(1E+100,SEARCH($E$2:$E$11,A2),$E$2:$E$11)
Here's a round about way that works, not all my own work but a mish mash of bits from other sources:
Assuming the sheet is setup as follows:
The formula to use is below, this must be entered using Ctrl+Shift+Enter
=INDEX($C$2:$C$8,MAX(IF(ISERROR(SEARCH($C$2:$C$8,A2)),-1,1)*(ROW($C$2:$C$8)-ROW($C$2)+1)))
Annotated version:
=INDEX([List of search terms],MAX(IF(ISERROR(SEARCH([List of search terms],[Cell to search])),-1,1)*(ROW([List of search terms])-ROW([Cell containing first search term])+1)))

Resources