Excel - VLOOKUP return based on partial string - excel

I am trying to get VLOOKUP to return a value based on a partial string. So I want to say: look up this string, look in the list and if you find a partial string matching it, return the date next to it. But not having much luck. In my example, B2 should show: April 9th as the first bit of the string in D2 matches.

Try this one... Will help you
=VLOOKUP(LEFT(A3,FIND(" ",A3,FIND(" ",A3)+1)-1),$D$3:$E$5,2,0)

Use:
=VLOOKUP(MID(A2,1,FIND(" ",A2,FIND(" ",A2)+1)-1),$D$2:$E$4,2,FALSE)
Results:

Or you can do the other way around and use combination of INDEX and MATCH (with wildcard match) - look at the picture:
=INDEX($D$1:$E$4,MATCH(D2&"*",$A$2:$A$4,0)+1,2)
INDEX MATCH example
Advantage is of this is that you do not assume a given pattern of your values. So it does not matter whether it is SPXL APR19 59P or SPXL APR19_____59P.
You can also use the asterisk on both sides "*"&[]&"*", so then you'll do an inside search.

Related

Finding a Specific Element Inside Other Formulas

I need help writing a function to find "Th+4" and ignore all other attached chemical elements.
Example of the data;
/HASr+(aq) 1.2595E-12
Sr+2 2.9449E-06
SrCl+ 1.4637E-10
SrCO3 (aq) 1.01E-10
SrF+ 2.1778E-11
SrHCO3+ 3.2969E-09
How can I find only Sr+2 and ignore all the others? For now, I was using this function to find it, but it displays all elements containing Sr2+.
=IF(ISERROR(FIND("Sr+2",A7,1)),B7,"")
Please help,
Thank you !
Your question is very vague, but I assume that when you "locate" your value, you want to return the value to the right.
You can use Index() and Match() to do this for you.
Assuming that your lookup range is column A, and the value to return is column B, this should work:
=INDEX(A:B,MATCH("Sr+2", A:A),2)
Breaking Down the Formula
Index()
- A:B is the entire range to index. Your lookup value is column A, and your return value is column B
- Match() is returning the row number, which we will show that below.
- 2 is column to cross reference the return value of the row from Match(). Since Match() gives us the row #, this gives us the column number to "pin-point" the return value
Match()
- "Sr+2" is the string to be searched for
- A:A is the location to search for this string.
This returns the row to your Index() function
An alternate method from using Index() & Match() is to use VLOOKUP(). This function essentially combines the two previous functions for the same purpose in your case.
=VLOOKUP("Sr+2",A:B,2)
Using the VLOOKUP() Function
Use VLOOKUP, one of the lookup and reference functions, when you need to find things in a table or a range by row. For example, look up a price of an automotive part by the part number.
In its simplest form, the VLOOKUP function says:
=VLOOKUP(Value you want to look up, range where you want to lookup the value, the column number in the range containing the return value, Exact Match or Approximate Match – indicated as 0/FALSE or 1/TRUE).
I also found that this works for my problem;
=IF((EXACT($AG$38,A7)),B7,"")
Thank you for all your answers :)!
Have a great day!

Search an array for a text string in a separate array, return that text string (Excel)

I have a column of text values (column C below), they are of varying length. I have a separate array of text values (column A below). I want a formula that will look through the strings in Column C and return the word from Column A that it matches. If there are multiple matches (rare, probably won't happen), it will only return one.
Please see my example:
Column D is the result I am looking for. As you can see, this will require some kind of fuzzy string matching. The word could appear anywhere in the cell. It doesn't need to be case sensitive. But I need it to pull that word out of the string as the result basically.
Thank you!
Use This:
=INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$5)/(ISNUMBER(SEARCH($A$2:$A$5,C2))),1))
One more, slightly simpler:
=IF(COUNTIF($C$1:$C$100," * "&A2&" * ")>0,A2,"")
You can also try this formula =INDEX(A:A,SUMPRODUCT(MATCH(1,NOT(ISERR(SEARCH(A:A,C2)))*1,0))). Enter it using CTRL+SHIFT+ENTER since it is an array formula.
This formula seems to be working for me:
(Please use Ctrl+Shift+Enter for the array formula to take effect)
{=INDEX($A$2:$A$5,MATCH(1,COUNTIF(C2,"*"&$A$2:$A$5&"*"),0))}
Screenshot of Excel sheet

MATCH function does not work with words that have wildcards (*)

I am trying to match HA24BB-3-1LL with HA24B*-3-1** in Excel. Another example is matching HA24FB-3-1LL with HA24F*-3-1**.
However, when I performed the regular match function, these could not be matched.
col A col B
1 HA24BB-3-1LL HA24F*-3-1**
2 HA24FB-3-1LL HA24B*-3-1**
What I tried:
=MATCH(A1,B:B,0)
It should return 2 but it returns #N/A.
May I know why?
I thought Excel match function works with wildcard. Is there a way to enable it?
You can match with wildcards, but the wildcards have to be in your lookup value (first position in the formula). If they are in the lookup array (second position in the formula) they are not wildcards, just literal *s in the cell values.
So you can find matches to strings like HA24B*-3-1** in your first column by using the formula: =MATCH(B1,A:A,0), but not the other way around, as your formula is set up.
Also, if you are looking for things that match HA24B[one character]-3-1[two characters] your search string should instead be HA24B?-3-1??. The * will match a string of any length, so it is redundant to put two of them at the end of your search string, and using them will also find you matches to strings like HA24Babcdedfghijklmnopqrstuvwxyz-3-1abcdefghijklmnopqrstuvwxyz. Which may be what you want, and if it is leave it as is (minus the second * at the end). The ? matches a single character, which I am assuming is what you are looking for since you used ** in your question.

MS Excel: remove number of characters after a specific character in a string

I have a column with values like
WI60P-14E64F5167E6-01138
or
WI60-34D03E185267-01051
etc....
i need to find the first occurrence of - till the second occurrence of - and remove the resulting character.
I am using this function =MID(A1,FIND("-",A1),13) which returns me -34D03E185267 or -14E64F5167E6 from the above strings.
But I want the output like WI60P-01138 or WI60-01051
Can anyone help me?
Assuming that the length of text between the two hyphens never varies, you can use your existing function, along with SUBSTITUTE to get the desired string, like so:
=SUBSTITUTE(A1,MID(A1,FIND("-",A1),13),"")
Alternately, you can use FIND to get the hyphen positions and again use SUBSTITUTE to get the replaced string, like so:
=SUBSTITUTE(A1,MID(A1,FIND("-",A1),FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)),"")
Notice that one of the FIND expressions takes 3 parameters - by passing FIND("-",A1) + 1 as the third parameter, we get the second occurence of '-' within the cell.
This will work for any position of the two hyphens:
=CONCATENATE(MID(A1;FIND("-";A1)+1;FIND("-";A1;FIND("-";A1)+1)-FIND("-";A1)-1))
Solution using multiple cells as support (with dynamic length of the string):
Put this in cell B1 to obtain the first part of the code:
=MID(A1,1,FIND("-",A1)-1)
Put this in cell C1 to obtain the last part of the code:
=MID(A1,FIND("-",A1)+1,LEN(A1))
Put this in cell D1 to concatenate both and get your result:
=concat(B1,C1)
Solution in a single cell (with dynamic length of the string)
Put this in cell B1 to get the same result as above :
=concat(MID(A1,1,FIND("-",A1)-1),MID(MID(A1,FIND("-",A1)+1,LEN(A1)),FIND("-",MID(A1,FIND("-",A1)+1,LEN(A1))),LEN(MID(A1,FIND("-",A1)+1,LEN(A1)))))

Check whether a cell contains a substring

Is there an in-built function to check if a cell contains a given character/substring?
It would mean you can apply textual functions like Left/Right/Mid on a conditional basis without throwing errors when delimiting characters are absent.
Try using this:
=ISNUMBER(SEARCH("Some Text", A3))
This will return TRUE if cell A3 contains Some Text.
The following formula determines if the text "CHECK" appears in cell C10. If it does not, the result is blank. If it does, the result is the work "CHECK".
=IF(ISERROR(FIND("CHECK",C10,1)),"","CHECK")
For those who would like to do this using a single function inside the IF statement, I use
=IF(COUNTIF(A1,"*TEXT*"),TrueValue,FalseValue)
to see if the substring TEXT is in cell A1
[NOTE: TEXT needs to have asterisks around it]
This formula seems more intuitive to me:
=SUBSTITUTE(A1,"SomeText","") <> A1
this returns TRUE if "SomeText" is contained within A1.
The IsNumber/Search and IsError/Find formulas mentioned in the other answers certainly do work, but I always find myself needing to look at the help or experimenting in Excel too often with those ones.
Check out the FIND() function in Excel.
Syntax:
FIND( substring, string, [start_position])
Returns #VALUE! if it doesn't find the substring.
It's an old question but I think it is still valid.
Since there is no CONTAINS function, why not declare it in VBA?
The code below uses the VBA Instr function, which looks for a substring in a string. It returns 0 when the string is not found.
Public Function CONTAINS(TextString As String, SubString As String) As Integer
CONTAINS = InStr(1, TextString, SubString)
End Function
I like Rink.Attendant.6 answer. I actually want to check for multiple strings and did it this way:
First the situation: Names that can be home builders or community names and I need to bucket the builders as one group. To do this I am looking for the word "builder" or "construction", etc. So -
=IF(OR(COUNTIF(A1,"*builder*"),COUNTIF(A1,"*builder*")),"Builder","Community")
This is an old question but a solution for those using Excel 2016 or newer is you can remove the need for nested if structures by using the new IFS( condition1, return1 [,condition2, return2] ...) conditional.
I have formatted it to make it visually clearer on how to use it for the case of this question:
=IFS(
ISERROR(SEARCH("String1",A1))=FALSE,"Something1",
ISERROR(SEARCH("String2",A1))=FALSE,"Something2",
ISERROR(SEARCH("String3",A1))=FALSE,"Something3"
)
Since SEARCH returns an error if a string is not found I wrapped it with an ISERROR(...)=FALSE to check for truth and then return the value wanted. It would be great if SEARCH returned 0 instead of an error for readability, but thats just how it works unfortunately.
Another note of importance is that IFS will return the match that it finds first and thus ordering is important. For example if my strings were Surf, Surfing, Surfs as String1,String2,String3 above and my cells string was Surfing it would match on the first term instead of the second because of the substring being Surf. Thus common denominators need to be last in the list. My IFS would need to be ordered Surfing, Surfs, Surf to work correctly (swapping Surfing and Surfs would also work in this simple example), but Surf would need to be last.
Why not simply
COUNTIF(A1,"*xyz*")
This searches for any appearence of "xyz" in cell A1.
It returns "1" when found, and "0" when not found.
Attention, the search is not case sensitive, so any of xyz, XYZ, XyZ, and so on will be found. It finds this as substrings in the cell, so also for abcxYz you get a hit.
If you do not want to write your search string into the formula itself, you can use
COUNTIF(A1,"*" & B1 & "*")
and enter your search string into B1. - Attention, when B1 is empty, the formula will return "found" ("1") as the search string is then read as "**".
Interesting *
=COUNT(MATCH("*SomeText*",A1,))
=COUNTA(VLOOKUP("*SomeText*",A1,1,))
=COUNTA(HLOOKUP("*SomeText*",A1,1,))
this returns 1 if "SomeText" is contained within A1.
Here is the formula I'm using
=IF( ISNUMBER(FIND(".",A1)), LEN(A1) - FIND(".",A1), 0 )

Resources