Excel Index Match with text string - excel-formula

enter image description hereI am trying to write a formula that will allow me to return a value based on it being matched with a short text string that is contained in a longer text string. Please see below. I would like the "Unit Time" column in the second table to retrieve that corresponding value from the first table by matching the shorter text string in the product column of the first table in the longer product name in the second table. Any thoughts would be appreciated.
Thanks
excel

If the product will always be XX-XX then you can use:
=INDEX(B:B,MATCH(Left(D2,5),A:A,0))
If the product can be more than 2 characters around the dash, then you'll have to use the Find() formula to get the position of the end of the product in col D instead of Left().
To account for row 4 as Scott pointed out:
=INDEX(B:B,MATCH(LEFT(D2,FIND("-",D2,4)-1),A:A,0))
This will find the second dash in the string and use the variable length for the Left() function.

Related

Excel Formula: If cell contains "...", then insert "..." into adjacent cell, based on acronym rules

I have a long list of item names based on their SKUs, for example:
SKU = ITEM NAME
TS = Men’s Tee
PP = Men’s Pants
PT = Plain Pocket Tee
MS = Men's Shorts
B = Boxer
BB = Boxer Briefs
How do I generate Item Names in Column B, based on the sku in Column C?
Currently, I am using
=IF(ISNUMBER(SEARCH("...",C1)), "...")
This formula works, but manually entering "B", and "Boxer" in each cell is tedious. How do I automate this?
I found something similar here, but I don't know how to reverse engineer it.
Suppose you have a structured reference table called SKU as below:
Please note, you must sort the Code column in alphabetic order (A-Z).
Suppose you want to return the product name in Column B based on the SKU code in Column C, in Cell B2, enter the following formula and drag it down:
=LOOKUP(2,1/--ISNUMBER(SEARCH(SKU[Code],C2)),SKU[Name])
See below demonstration:
The key step here is to set up a lookup table first, then you will be able to look up the product name based on the SKU code (use SEARCH function).
================ Added Solution ================
To fix the issue of having product code within another product code and not returning the correct product name, please use the following formula instead (assuming all your product codes are consist of letters only without any numbers):
=LOOKUP(LEFT(C2,MIN(IFERROR(FIND(ROW($1:$10)-1,C2),LEN(C2)))-1),SKU[Code],SKU[Name])
The key of the above formula is to find where the product code ends within each text string, for example, the product codes ends on the second character of this text string PP416, and the following formula will return number 2 to indicate that:
=MIN(IFERROR(FIND(ROW($1:$10)-1,C2),LEN(C2))
Then you can use the LEFT function to extract the product code out of the text string, and use the LOOKUP function to return the corresponding product description.
If your version of Excel has XLOOKUP function, I suggest you replace LOOKUP with XLOOKUP, the rest of the formula does not change. You can google how to use XLOOKUP as it is more powerful than LOOKUP.
Let me know if you have any question :)

Excel INDEX MATCH to find exact location name from string text

I have in my Excel workbook two tables:
In first table I have string text full sentence (in colunmn C) in many rows where is described in sentence some place names (some rows don't have those location names) and
in second table I have place names list (every place name have also geographical X (latitude) and Y (longitud) coordinates.
I want to search inside first table string text location names which have exact match to the placename_table list and show founded place name in first tabele column D. I tried this formula in column D, it almost working, but it finds first match of placename_tabele and it is not correct what was mean in first table string.
I use Excel 2013
=IFERROR(INDEX(Placename_table; SMALL(IF(COUNTIF($C2;"*"&Placename_table&"*"); MATCH(ROW(ANIMI); ROW(Placename_table)); ""); COLUMNS($A$1:A1))); "-")
placename_tabels
You may try FILTERXML() with index. Put below formula in D2 cell then drag down and right.
=IFERROR(INDEX(FILTERXML("<t><s>"&SUBSTITUTE($C2," ","</s><s>")&"</s></t>","//s[starts-with(., 'placement')]"),COLUMN(A$1)),"")

Using Excel index/match to search a column containing numbers and text

I have 2 tables:
tblCodes contains 2 columns:
Code (4-char code can be text or numeric), Code Name (text description)
tblSerialNum contains 3 columns:
SerialNum column (can be text or numeric),
Code column is 1st 4 chars of SerialNum using LEFT() function,
Code Name column uses index/match to look up Code Name that matches Code:
=INDEX(tblCodes[Code Name],MATCH([#Code],tblCodes[Code],0))
sample tables
The problem is with the serial # 1234001: the MATCH doesn't work when the Code is all numeric because the LEFT() function always returns a string "1234" and it doesn't find it in the code table because it reads as number 1234.
I can't convert the values in the tlbSerialNum[Code] column to numeric because some are text "x333".
I've tried formatting the tblCodes[Code] column to text, but the function still treats 1234 as numeric.
I can type '1234 into tblCodes[Code] using an apostrophe to force it as a text, but I don't want to rely on my users to always remember to enter it that way.
Any suggestions?
Change everything to text in the formula:
=INDEX(tblCodes[Code Name],MATCH([#Code]&"",tblCodes[Code]&"",0))
This is now an array formula and depending on one's version may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Searching for Uppercase words in multiple cells and returning in a specific cell

I have a spreadsheet which contains addresses. The City is shown in uppercase, however, the city could be present on any of the 5 columns. I am wanting to create a formula which will search the 5 columns in the row and return the City, where the whole word in in uppercase.
I have searched this site and others and I can only fnd code which will split out words that start with uppercase.
Given that the city name will be the only word in uppercase in the 5-column range, you can use either of the following formulas to find the city name:
=INDEX(AV2:AZ2,SUMPRODUCT(EXACT(UPPER(AV2:AZ2),AV2:AZ2)*NOT(ISBLANK(AV2:AZ2))*COLUMN(AV2:AZ2)))
or
=INDEX(AV2:AZ2,AGGREGATE(15,7,COLUMN(AV2:AZ2)/(EXACT(UPPER(AV2:AZ2),AV2:AZ2)*NOT(ISBLANK(AV2:AZ2))),1))
Replace AV2:AZ2 with the first row of your actual data, and drag the formula down to apply across board.
The logic is to:
use UPPER function to convert all text strings in the 5-column range to uppercase, and compare the converted string with the original one using EXACT, the only match would be city name;
use either AGGREGATE or SUMPRODUCT to find out the column number (between 1 to 5) where the city name locates, with the help of using NOT+ISBLANK to eliminate the impact of blank cells;
use the location number in an INDEX formula to return the actual city name.
See below screen-shot for more clarifications.
Although both of them are array formulas, there is no need to press Ctrl+Shift+Enter when using SUMPRODUCT or AGGREGATE in this case.
Cheers :)

Excel Call text in a cell as a factor in a formula

I have a need to count cells with a particular string of text. I have a list of each string of text to be counted.
I am forming a query using CountIf in the form:
=COUNTIF(C1:C4929,"String")
where every occurrence of 'String' is counted and output.
I would like to show the counts for each string of text in a column alongside the String. I have created a column with one string per cell.
What I would love to be able to do is call the string in the cell into the CountIf function, sort of like:
=COUNTIF(C1:C4929, "Whatever's in the column to the left of this output cell")
But I can't work it out. Am looking and will update here IMMEDIATELY if I work it out.
EDIT:
DONE!
=COUNTIF(C1:C4929,INDIRECT("RC[-1]",0))
Please try =COUNTIF(C1:C4929,"="&D1) copied down from E1, where ColumnD contains your strings.

Resources