I've got a weird Excel problem that is giving me a mind block. Basically, this is what I've got:
Column A contains strings of text, which all contain company names and a bunch of other info. I'd like to strip out those names. I've got a list of the names I'm searching for.
**Contractor**
CompanyA
CompanyB
CompanyC
CompanyD
And strings like this:
CompanyA REQ# G-FMR-036 PT 2
CompanyA Pad AN Structural Steel ()
COMPANYC REQ# 54
CompanyA REQ# G-FMR-049
What I would like is the formula to return whichever of the company names appears in that string. My first thought was a giant nested formula of IFs and SEARCHes but I know there has to be a better way.
With the list to search in A1:A4 and the list of company names in B1:B4, this array formula, entered with CtrlShiftEnter will do it:
=INDEX($B$1:$B$4,MATCH(TRUE,ISNUMBER(SEARCH($B$1:$B$4,A1)),0))
A bit of a kludge but better than nested IFs:
I am explaining for the example you gave above (4 companies); you should be able to figure out how to extend this.
In column A have your strings that include company names and the extra stuff. Let's assume A1 has some column title, and your 4 strings are in A2, A3, A4, A5.
In cells C1, D1, E1, F1 have the "clean" four company names.
In C2 have this formula:
=IF(ISERROR(FIND(UPPER(C$1), UPPER($A2))),"",C$1)
Then copy cell C2 to all the cells in C2:F5 . The formula will update automatically to fit each cell.
Then, in cell H2 have this formula:
=C2&D2&E2&F2
and then copy/paste it to H3, H4, H5.
In column H you will get what you are looking for.
Of course this assumes you have only one matching company name in each cell in column A, and that the names are exactly (up to case-sensitivity) the same as the company names in cells C1:F1 .
I take it that some of the company names contain spaces, otherwise you could just use:
=left(a1,find(" ",a1)-1)
If you need to compare the contents of the string against a list of companies, then with the list in a named range "CompanyList"; one entry per row; you could try something like:
=IFERROR(LOOKUP(2,1/ISNUMBER(SEARCH(CompanyList&"*",A1)),CompanyList),"Not in List")
However, if some names are similar, you will need to pay attention to the order in the list, as the formula will return the last entry that matches. So you want to put the longest string in Company List last.
This is what I've created so far, although I imagine there has to be a better way than nested formulas like whoa. I mean, it works, but it makes me want to cry.
=IF(ISNUMBER(SEARCH(T$3,B3)),"CompanyA",IF(ISNUMBER(SEARCH(T$4,B3)),"CompanyB",IF(ISNUMBER(SEARCH(T$5,B3)),"CompanyC",IF(ISNUMBER(SEARCH(T$6,B3)),"CompanyD","Other"))))
Related
I have an Excel list with course names and their number like this:
V3 Varikosis Masterclass
B3 Botulinumtoxin Premiumkurs, H2
M1 Mykologie Basiskurs [Digital], D1 Dermatoskopie Basiskurs [Digital]
B5 BTX Workshop (21.11.21) (sometimes there are random numbers that have nothing to do with the code like a date)
It's very messy since some people ordered two courses, so I can't just take the first two symbols from each cell. Is there a formula that finds and extracts a single letter and number combination from a string of text?
If you do not have any other cases e.g. max number of courses is 2 and comma and space is always the same it is rather straightforward.
=LEFT(A3,2)
=IFERROR(MID(A3,SEARCH(",",A3,1)+2,2),"")
I need a function that will search a cell for many keyword text strings (model numbers) and return each model number that it finds. In all my research I have only found solutions that provide one matching keyword, but I would like all matching keywords.
An example of a solution only finding one keyword: Excel: Search for a list of strings within a particular string using array formulas?
Example of what I would like:
Cell to search in (A1) contains:
A-007858 CustomerCompanyName D1001, S1135, BE60 and R235 New 6 and 8 Packs
Search Keywords (on separate worksheet A1-A70):
A32: D1001
A43: S1135
A6: BE60
A64: R235
Desired Output:
Each model number found (D1001, S1135, BE60, R235) displayed in cells B1, C1, D1, and E1 next to the cell that was searched (A1). The order of the model numbers is not important. I would prefer an Excel function solution rather than VBA.
Put this formula in B1 and copy over:
=IFERROR(INDEX(Sheet2!$A$1:$A$70,AGGREGATE(15,6,ROW(Sheet2!$A$1:$A$70)/(ISNUMBER(SEARCH(Sheet2!$A$1:$A$70,$A1))),COLUMN(A:A))),"")
Replace Sheet2 with the name of the sheet on which your list resides.
It will be in order of the list on the other sheet.
If you don't have too many keywords you can do this fairly simply:
B1 = IF(ISERROR(SEARCH("D1001",A1)),"","D1001")
where you can replace "D1001" with a reference to the cell in the other sheet. C1:E1 would be analogous.
If you have a lot, then you'll need something more involved like #ScottCraner suggests.
I am trying to create a decoding macro. I have different combinations of letters in each cell on one sheet. For example, in cell B2 I would have something like "ABC." On a different sheet I have a table that matches letters to numbers, so I want the output in the new cell to be "123" in that case. I know how to use VLOOKUP on an entire cell, but cannot figure out how to use it on individual parts and then concatenate the results back together in the new cell.
This is what I've figured out so far. I think I need INDIRECT as part of it so I can reference the cell, but I cannot figure out how to look up the different portions of the cell. I do not want to create new columns to split the letter combinations up if possible.
=IFERROR(VLOOKUP("not sure??",'Conversion Table'!A4:B19,2,FALSE),"")
Thanks!
I'm assuming your cell B2 is limited to 3 chars only, and it's the same everywhere. In this case, you can do:
=CONCATENATE(VLOOKUP(MID(B2,1,1),'Conversion Table'!$A$4:$B$19,2,0),VLOOKUP(MID(B2,2,1),'Conversion Table'!$A$4:$B$19,2,0),VLOOKUP(MID(B2,3,1),'Conversion Table'!$A$4:$B$19,2,0))
If you have more chars, only add them using concatenate and select them one by one using MID.
Edit - locked the lookup table.
I think what you may be looking for is this:
A B C D
1 =""
2 ABC =IFERROR(VLOOKUP( =D1&C2
B2,
'Conversion Table'!$A$4:$B$19,
2,FALSE),"")
3 XYZ =IFERROR(VLOOKUP( =D2&C3
B3,
'Conversion Table'!$A$4:$B$19,
2,FALSE),"")
4 PQR =IFERROR(VLOOKUP( =D3&C4
B4,
'Conversion Table'!$A$4:$B$19,
2,FALSE),"")
5 DEF =IFERROR(VLOOKUP( =D4&C5
B5,
'Conversion Table'!$A$4:$B$19,
2,FALSE),"")
The "Final Answer" appears in cell D5
I need a formula that will look up a value in a 2-dimensional range and return the coordinates or cell address of the matching cell. For example:
R A B C
1 John Matt Pete
2 Sara Bret Chad
3 Lila Maya Cami
I want to search the range A1:C3 for Chad and return C2 or 2,3. How can I accomplish this using Excel formulas? (I'll actually end up applying this to Google Sheets).
Thanks!
Old question, but I thought I'd share a much simpler and elegant answer here that doesn't involve helper columns or complicated formulas, so that more people will get things done easier. Assuming that the table contains unique values and that you use E1 to store your search string Chad and E2 to display the result:
if you want the row and column result of 2,3 in E2:
=SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)) & "," & SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))
if you want the R1C1 style cell address string of C2 in E2:
=ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3)))
if you want the found cell's contents of Chad in E2:
=INDIRECT(ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))))
How things work:
SUMPRODUCT returns in this case the sum of the products between a boolean array of TRUE (searched value found in cell) and FALSE (searched value not found in cell) for every cell in the table and the corresponding row/column (absolute) numbers of those cells in the sheet; thus, the result is essentially the row/column (absolute) number of the cell where the value has been found, since TRUE=1 and FALSE=0 in mathematical terms
ADDRESS returns a cell's address as text (not as reference!)
INDIRECT returns the reference corresponding to a cell's text address
Source and credit goes to: this answer by XOR LX. Could have added the link in a comment, mentioning the duplicate question, but I wanted to expand and explain the answer a little bit, therefore more characters were needed.
Assuming you're using Excel 2007 and above.
You will need a helper column. If your table looks like in your example, in cell D1 write:
=IFERROR(MATCH($E$1,$A1:$C1,0),0)
And drag it down. Then in cell E1 write your search value ("Chad" for instance). Then you have your search result in cell E2 with this formula:
=IF(MAX($D:$D)=0,NA(),MATCH(MAX($D:$D),$D:$D,1)&","&MAX($D:$D))
If you want a simpler solution, it is possible to use only one helper (or not at all, at the cost of a complicated formulae).
Let's say I take your example. I will use the D column to display result :
In D1, I put the name I want to find : Chad
In D2, I put the helper that will return an Index of the value searched (-1 if not found) : =IFERROR(MATCH(D1,SPLIT(TEXTJOIN(";",TRUE,A1:C3),";"),0),-1)
In D3, I put the formulae to get the row,column value (FALSE if not found) : =IF(D2<>-1,ROUNDUP(DIVIDE(D2,COLUMNS(A1:C3))) & "," & IF(MOD(D2,COLUMNS(A1:C3))=0,COLUMNS(A1:C3),MOD(D2,COLUMNS(A1:C3))))
If you really want to use only one formulae, it is possible in D3 to replace all references to D2 by the formulae used in D2.
This formula returns the row and column number of a given value in a two-dimensional array.
=LET(
array, B2:D4,
findvalues, C7,
arrayrows, ROWS(array),
arraycols, COLUMNS(array),
rowindex, SEQUENCE(arrayrows*arraycols,,1,1/arraycols),
colindex, MOD(SEQUENCE(arrayrows*arraycols,,0),arraycols)+1,
flatarray, INDEX(array,rowindex,colindex),
valueflatindex, MATCH(findvalues,flatarray,0),
valuerow, ROUNDUP(valueflatindex/arraycols,0),
valuecol, MOD(valueflatindex-1,arraycols)+1,
absvaluerow, MIN(ROW(array))+valuerow-1,
absvaluecol, MIN(COLUMN(array))+valuecol-1,
CHOOSE({1,2},absvaluerow,absvaluecol)
)
A B C D E
1
2 John Matt Pete
3 Sara Bret Chad
4 Lila Maya Cami
5
6
7 find: Chad
8 formula: 3 4
More precisely, this formula scans a given array row by row and returns the address of the first occurrence of a given value.
If you need the row and column numbers relative to the array's top left cell, then in CHOOSE(...), instead of absvaluerow/absvaluecol, use valuerow/valuecol.
If you want the values to be comma separated and in one cell, instead of CHOOSE(...), use absvaluerow & "," & absvaluecol
If your Excel version does not support the latest functions, such as LET, the formula should still work if you rewrite it so that it does not use the LET variables.
Find Multiple Values
You can also find multiple values in an array using this formula as explained in my answer in this thread.
I need to assign a status to a row based on a VLOOKUP query between two worksheets. The problem is that the identifier is not always unique. However, the identifier + a date value should be unique. I wanted to use:
=VLOOKUP(A3&H3,'OtherSheet'!D:E,1,FALSE)
with A3 being the identifier and H3 being the corresponding date. D in the other sheet is the identifier and E is the date column. However, I keep getting #N/A.
Does this mean that there are no matches with the "identifier+date" or is Excel looking for "identifier+date" in either column D or E? If the latter is true, how can I let Excel concatenate D and E when matching to the search pattern?
There's work around without using CTRL+Shift+Enter.
Use this formula that will match A3 in D column of othersheet and H3 with the date in column E of the othersheet.
=INDEX(OtherSheet!F:F,MATCH(1,INDEX((OtherSheet!D:D=A3)*(OtherSheet!E:E=H3),),0))
The formula will return data from F column of OtherSheet.
You can modify the range OtherSheet!F:F as appropriate.
That formula is looking to find A3 concatenated with H3 (identifier&date) in OtherSheet ColumnD that contains only identifiers, so will inevitably fail. Yes, Excel is looking for “identifier+date” in column D.
Excel will happily concatenate A3 with H3 ‘on the fly’ (within a formula) but will not so happily concatenate OtherSheet ColumnD and ColumnE values in the same way. The conventional solution, because usually simplest in a case like this, is to prepare for the VLOOKUP by adding a helper column that concatenates the D and E values while preserving these in the same row as the value sought.
Because VLOOKUP will only look to the right this is usually a column that is added to the left of the value being searched for, so say either in C or by insertion of a column immediately to the right of C. However, since you are only checking a single column the location is not critical. You might add this (in OtherSheet) as ColumnZ, with a formula such as:
=D2&E2
copied down to suit*. Again because you are only checking a single column it does not matter which row such a formula is placed in.
However, because only checking whether A3&H3 exists in OtherSheet a simple alternative may be to apply COUNTIFS:
=COUNTIFS(OtherSheet!D:D,A3,OtherSheet!E:E,H3)
Any result other than 0 from this should indicate that the combination being tested for exists in OtherSheet – without need for a helper column.
* Depending on the format of your identifiers it is possible that concatenation may introduce ambiguity. For example ID90 concatenated with 11/1/15 may not be distinguishable from ID901 concatenated with 1/1/15, so it may be advisable if taking this approach to introduce a delimiter, in both the VLOOKUP formula (say A3&"|"&H3 rather than just A3&H3) and therefore also in the helper column, say =D2&"|"&E2.
You likely would want to use Index/Match instead. Vlookup is tricky when it comes to searches for multiple things. Here's the way you would use Index/Match:
Without knowing how your spreadsheet is set up, here's how you could do it:
If I understand correctly, you want to use A3 to find the match in OtherSheet!D, and H3's match in OtherSheet!E. Index match is perfect for this. Instead of vLookup, use
=Index(OtherSheet!D:D&","&Text(OtherSheet!E:E,"mm-dd-yyyy"),Match(A3&H3,OtherSheet!D&OtherSheet!E,0)), and enter with CTRL+SHIFT+ENTER.
What the Index() will return is the concatenated Identifier and Date, separated with a comma. If, though, you have a table like this:
That index/match formula will return "Batman". The index to return is the named range G2:G5. You're looking for a match on A1 (the Identifier) and B1 (the Date), then you're searching for (in the order you just put) the Identifier to be in the range E2:E5, and the Date to be in F2:F5. When there's a match for both, it returns the name in G2:G5.
Here's a link to a site on using Index/Match, and another and its advantages over vlookup.