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

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.

Related

Finding the index of a matching wildcard in 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))

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

Nested IF(AND(OR statement

Here is my current formula
=IF(OM2=0,"No",IF(OM2=4(OR(5,11,12,16,17))*AND(F2="Double"),"Yes",IF(OM2=1(OR(2,3,6,7,8,9,10,13,14,15))*AND(F2="Triple"),"Yes","No")))
I'm trying to get OU to be yes if OM is 4,5,11,12,16,or 17 and F is Double.
Also, to get OU to be yes if OM is 1,2,3,6,7,8,9,10,13,or 15 and F is Triple.
I have checked F2 and it correctly results "Double" or "Triple" accordingly with correct spelling and no extra spaces.
I am still getting "No" being resulted, see pic below:
Thanks for any help!
Try to write OR(OM2 = x, OM2=y, OM2 = z ...) instead of what you wrote.
This should work.
As the other responders said you should really think about making a lookup tables.
In addition, if you use Excel 2013 onwards, it is much easier if you convert your normal table into "Excel" table (Ctrl - T will do it). Google more about "Excel tables" to learn about their benefits vs traditional tables.
After that, set up 2 lookup tables, Table 1 and Table 2 (they themselves should also be Excel tables) as in the photo.
Then your formula will be:
=OR(SUMPRODUCT(--(Table1[OM]=[#OM]),--(Table1[F]=[#F])),SUMPRODUCT(--(Table2[OM]=[#OM]),--(Table2[F]=[#F])))
When you write up this formula, you can just select the cells in the respective lookup tables, Excel will automatically turn them into table named ranges as you see above.
Another option would be to use a lookup table to map your value of OM to the expected value of OU.
For example, if you had a sheet named "Lookup" with the following data:
| A | B
1 | 1 | Triple
2 | 2 | Triple
...
5 | 5 | Double
Then you could use something like
IF(VLOOKUP(OM2,Lookup!$A$1:$B$16,2,FALSE)=OU2,"Yes","No")

Excel = operator isn't working as expected with multiple tabs

I have an Excel-file with 2 tabs:
Tab1
ActorID | ActorName
--------------------
4321 | ActorName1
4322 | ActorName2
4323 | ActorName3
4324 | ActorName4
In the second tab I want to put in the name of the actor and see if it's in the array
So I used this formula: =(Tab1!A1:A10="ActorName1"), but I get FALSE. When I use the same formula in the first tab (=(A1:A10="ActorName1")) I get TRUE.
I don't understand why I get FALSE if the formula is used in another tab :/
The formula works on the tab only if the name you are searching is the first. You are trying to compare an array to a single item, Excel will only look at the first.
To search a range of names use MATCH(). To return TRUE/FALSE wrap it in ISNUMBER(), as MATCH will return a number if found or an error if not found.
=ISNUMBER(MATCH("ActorName1",Tab1!A1:A10,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