The tutorial explains the syntax of the Excel FIND and SEARCH functions and provides formula examples of advanced non-trivial uses.
In the last article, we covered the basics of the Excel Find and Replace dialog. In many situations, however, you may want Excel to find and extract data from other cells automatically based on your criteria. So, let's have a closer look at what the Excel search functions have to offer.
Excel FIND function
The FIND function in Excel is used to return the position of a specific character or substring within a text string.
The syntax of the Excel Find function is as follows:
The first 2 arguments are required, the last one is optional.
- Find_text - the character or substring you want to find.
- Within_text - the text string to be searched within. Usually it's supplied as a cell reference, but you can also type the string directly in the formula.
- Start_num - an optional argument that specifies from which character the search shall begin. If omitted, the search starts from the 1st character of the within_text string.
If the FIND function does not find the find_text character(s), a #VALUE! error is returned.
For example, the formula =FIND("d", "find")
returns 4 because "d" is the 4th letter in the word "find". The formula =FIND("a", "find")
returns an error because there is no "a" in "find".
Excel FIND function - things to remember!
To correctly use a FIND formula in Excel, keep in mind the following simple facts:
- The FIND function is case sensitive. If you are looking for a case-insensitive match, use the SEARCH function.
- The FIND function in Excel does not allow using wildcard characters.
- If the find_text argument contains several characters, the FIND function returns the position of the first character. For example, the formula FIND("ap","happy") returns 2 because "a" in the 2nd letter in the word "happy".
- If within_text contains several occurrences of find_text, the first occurrence is returned. For example, FIND("l", "hello") returns 3, which is the position of the first "l" character in the word "hello".
- If find_text is an empty string "", the Excel FIND formula returns the first character in the search string.
- The Excel FIND function returns the #VALUE! error if any of the following occurs:
- Find_text does not exist in within_text.
- Start_num contains more characters than within_text.
- Start_num is 0 (zero) or a negative number.
Excel SEARCH function
The SEARCH function in Excel is very similar to FIND in that it also returns the location of a substring in a text string. Is syntax and arguments are akin to those of FIND:
Unlike FIND, the SEARCH function is case-insensitive and it allows using the wildcard characters, as demonstrated in the following example.
And here's a couple of basic Excel SEARCH formulas:
=SEARCH("market", "supermarket")
returns 6 because the substring "market" begins at the 6th character of the word "supermarket".
=SEARCH("e", "Excel")
returns 1 because "e" is the first character in the word "Excel", ignoring the case.
Like FIND, Excel's SEARCH function returns the #VALUE! error if:
- The value of the find_text argument is not found.
- The start_num argument is greater than the length of within_text.
- Start_num is equal to or less than zero.
Further on in this tutorial, you will find a few more meaningful formula examples that demonstrate how to use SEARCH function in Excel worksheets.
Excel FIND vs. Excel SEARCH
As already mentioned, the FIND and SEARCH functions in Excel are very much alike in terms of syntax and uses. However, they do have a couple of differences.
1. Case-sensitive FIND vs. case-insensitive SEARCH
The most essential difference between the Excel SEARCH and FIND functions is that SEARCH is case-insensitive, while FIND is case-sensitive.
For example, SEARCH("e", "Excel") returns 1 because it ignores the case of "E", while FIND("e", "Excel") returns 4 because it minds the case.
2. Search with wildcard characters
Unlike FIND, the Excel SEARCH function accepts wildcard characters in the find_text argument:
- A question mark (?) matches one character, and
- An asterisk (*) matches any series of characters.
To see how it works on real data, consider the following example:
As you see in the screenshot above, the formula SEARCH("function*2013", A2) returns the position of the first character ("f") in the substring if the text string referred to in the within_text argument contains both "function" and "2013", no matter how many other characters there are in between.
Tip. To find an actual question mark (?) or asterisk (*), type a tilde (~) before the corresponding character.
Excel FIND and SEARCH formula examples
In practice, the Excel FIND and SEARCH functions are rarely used on their own. Typically, you would utilize them in combination with other functions such as MID, LEFT or RIGHT, and the following formula examples demonstrate some real-life uses.
Example 1. Find a string preceding or following a given character
This example shows how you can find and extract all characters in a text string to the left or to the right of a specific character. To make things easier to understand, consider the following example.
Supposing you have a column of names (column A) and you want to pull the First name and Last name into separate columns.
To get the first name, you can use FIND (or SEARCH) in conjunction with the LEFT function:
=LEFT(A2, FIND(" ", A2)-1)
or
=LEFT(A2, SEARCH(" ", A2)-1)
As you probably know, the Excel LEFT function returns the specified number of left-most characters in a string. And you use the FIND function to determine the position of a space (" ") to let the LEFT function know how many characters to extract. At that, you subtract 1 from the space's position because you don't want the returned value to include the space.
To extract the last name, use the combination of the RIGHT, FIND / SEARCH and LEN functions. The LEN function is needed to get the total number of characters in the string, from which you subtract the position of the space:
=RIGHT(A2,LEN(A2)-FIND(" ",A2))
or
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2))
The following screenshot demonstrates the result:
For more complex scenarios, such as extracting a middle name or splitting names with suffixes, please see How to split cells in Excel using formulas.
Example 2. Find Nth occurrence of a given character in a text string
Supposing you have some text strings in column A, say a list of SKUs, and you want to find the position of the 2nd dash in a string. The following formula works a treat:
=FIND("-", A2, FIND("-",A2)+1)
The first two arguments are easy to interpret: locate a dash ("-") in cell A2. In the third argument (start_num), you embed another FIND function that tells Excel to start searching beginning with the character that comes right after the first occurrence of dash (FIND("-",A2)+1).
To return the position of the 3rd occurrence, you embed the above formula in the start_num argument of another FIND function and add 2 to the returned value:
=FIND("-",A2, FIND("-", A2, FIND("-",A2)+1) +2)
Another and probably a simpler way of finding the Nth occurrence of a given character is using the Excel FIND function in combination with CHAR and SUBSTITUTE:
=FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),3))
Where "-" is the character in question and "3" is the Nth occurrence you want to find.
In the above formula, the SUBSTITUTE function replaces the 3rd occurrence of dash ("-") with CHAR(1), which is the unprintable "Start of Heading" character in the ASCII system. Instead of CHAR(1) you can use any other unprintable character from 1 to 31. And then, the FIND function returns the position of that character in the text string. So, the general formula is as follows:
At first sight, it may seem that the above formulas have little practical value, but the next example will show how useful they are in solving real tasks.
Note. Please remember that the Excel FIND function is case-sensitive. In our example, this makes no difference, but if you are working with letters and you want a case-insensitive match, use the SEARCH function instead of FIND.
Example 3. Extract N characters following a certain character
To locate a substring of a given length within any text string, use Excel FIND or Excel SEARCH in combination with the MID function. The following example demonstrates how you can use such formulas in practice.
In our list of SKUs, supposing you want to find the first 3 characters following the first dash and pull them in another column.
If the group of characters preceding the first dash always contains the same number of items (e.g. 2 chars) this would be a trivial task. You could use the MID function to return 3 characters from a string, starting at position 4 (skipping the first 2 characters and a dash):
=MID(A2, 4, 3)
Translated into English, the formula says: "Look in cell A2, begin extracting from character 4, and return 3 characters".
However, in real-life worksheets, the substring you need to extract could start anywhere within the text string. In our example, you may not know how many characters precede the first dash. To cope with this challenge, use the FIND function to determine the starting point of the substring that you want to retrieve.
The FIND formula to return the position of the 1st dash is as follows:
=FIND("-",A2)
Because you want to start with the character that follows the dash, add 1 to the returned value and embed the above function in the second argument (start_num) of the MID function:
=MID(A2, FIND("-",A2)+1, 3)
In this scenario, the Excel SEARCH function works equally well:
=MID(A2, SEARCH("-",A2)+1, 3)
It's great, but what if the group of chars following the first dash contains a different number of characters? Hmm... this might be a problem:
As you see in the above screenshot, the formula works perfectly for rows 1 and 2. In rows 4 and 5, the second group contains 4 characters, but only the first 3 chars are returned. In rows 6 and 7, there are only 2 characters in the second group, and therefore our Excel Search formula returns a dash following them.
If you wanted to return all chars between the 1st and 2nd occurrences of a certain character (dash in this example), how would you proceed? Here is the answer:
=MID(A2, FIND("-",A2)+1, FIND("-", A2, FIND("-",A2)+1) - FIND("-",A2)-1)
For better understanding of this MID formula, let's examine its arguments one by one:
- 1st argument (text). It's the text string containing the characters you want to extract, cell A2 in this example.
- 2nd argument (start_position). Specifies the position of the first character you want to extract. You use the FIND function to locate the first dash in the string and add 1 to that value because you want to start with the character that follows the dash: FIND("-",A2)+1.
- 3rd argument (num_chars). Specifies the number of characters you want to return. In our formula, this is the trickiest part. You use two FIND (or SEARCH) functions, one determines the position of the first dash: FIND("-",A2). And the other returns the position of the second dash: FIND("-", A2, FIND("-",A2)+1). Then you subtract the former from the latter, and then subtract 1 because you don't want to include either dash. As the result, you will get the number of characters between the 1st and 2nd dashes, which is exactly what we are looking for. So, you feed that value to the num_chars argument of the MID function.
In a similar fashion, you can return 3 characters after the 2nd dash:
=MID(A2, FIND("-",A2, FIND("-", A2, FIND("-",A2)+1) +2), 3)
Or, extract all the characters between the 2nd and 3rd dashes:
=MID(A2, FIND("-", A2, FIND("-",A2)+1)+1, FIND("-",A2, FIND("-", A2, FIND("-",A2)+1) +2) - FIND("-", A2, FIND("-",A2)+1)-1)
Example 4. Find text between parentheses
Supposing you have some long text string in column A and you want to find and extract only the text enclosed in (parentheses).
To do this, you would need the MID function to return the desired number of characters from a string, and either Excel FIND or SEARCH function to determine where to start and how many characters to extract.
=MID(A2,SEARCH("(",A2)+1, SEARCH(")",A2)-SEARCH("(",A2)-1)
The logic of this formula is similar to the ones we discussed in the previous example. And again, the most complex part is the last argument that tells the formula how many characters to return. That pretty long expression in the num_chars argument does the following:
- First, you find the position of the closing parenthesis:
SEARCH(")",A2)
- After that you locate the position of the opening parenthesis:
SEARCH("(",A2)
- And then, you calculate the difference between the positions of the closing and opening parentheses and subtract 1 from that number, because you don't want either parenthesis in the result:
SEARCH(")",A2)-SEARCH("(",A2))-1
Naturally, nothing prevents you from using the Excel FIND function instead of SEARCH, because case-sensitivity or case-insensitivity makes no difference in this example.
Hopefully, this tutorial has shed some light on how to use SEARCH and FIND functions in Excel. In the next tutorial, we are going to closely examine the REPLACE function, so please stay tuned. Thank you for reading!
440 comments
Ma'am Lets say i have (3242*4643) and i have to extract from ( to * then what would i have to do?
Hi,
I have a problem in excel for find and pest,
The problem is "in a excel one page i have some numbers(123456), same page same number included in some words(abcd123456), so i can find out based on any formula please let me know, i am waiting.
Wonderful.
Thank you
Hello. This page is great. Thank you for sharing. Question, Your number 4, Find text between parentheses.... How do I apply this to multiple to an excel sheet that has many multiple lines of data? Each Line will have information in parentheses and we would like to pull the information within the parentheses from each line? Would I need to apply the formula =MID(D1,SEARCH("(",D1),SEARCH(")",D1)-SEARCH("(",D1)+1) to each line of data or is there an easy way to drag and select multiple line? (I know this formula includes the parentheses, which is what we want). Thanks!
Hello,
I'm afraid there's no easy way to solve your task with a formula. Using a VBA macro would be the best option here.
However, since we do not cover the programming area (VBA-related questions), I can advice you to try and look for the solution in VBA sections on mrexcel.com or excelforum.com.
Sorry I can't assist you better.
Hi,
Great set of examples on how to go about finding stuff in excel cells. I have a question though which i haven't found in your examples (or overlooked). I get a data dump with a json string in a cell. In json there is a lot of use of the " character. I can't seem to figure out how to look for a " in a cell.
Placing it in '"' (single quotes surrounding the ") didn't help either. Is this at all possible and if so how?
Hi Remi,
Please try to use one of the following formulas:
1. =FIND("""",A1)
2. =FIND(CHAR(34),A1)
Hope this will work for you.
In one tab ('Orchard details')of a spreadsheet I have a list of our 14 orchards and their respective varieties in each orchard. Some orchards have more than one variety. Some orchards have the same variety as other orchards. One field in the list is fallow at present. This list is in cells AA6:AA27. In another tab ('Orchard varieties'), I want to create just a list of the varieties that we grow taken from the 'Orchard details' list, reporting the (orchard varieties' tab in cells B93:B105. As we grub old orchards and plant new ones we may change the variety so the 'Orchard varieties' list would need to change as we replant our orchardsand record them in the 'Orchard details' list. Thank you.
Hi,
I have a column with multi-word text strings, I'd like to look in that text and for any cell in the column that contains one of three (e.g.) words, I'd like to return "X", else "Y".
For example, if the text contains 'green', 'blue' or 'purple' I'd like the result to be 'cool' else 'warm'
COL A COL B (result)
light pink warm
forest green cool
ocean blue cool
burnt orange warm
thanks,
sorry...didn't know spaces wouldn't be retained.
Col A | Col B(result)
light pink | warm
forest green | cool
ocean blue | cool
burnt orange | warm
Nevermind...unless there is an easier solution.
This works:
=IFERROR(IF(FIND("GREEN",$BJ34),"Cool","Warm"),IFERROR(IF(FIND("BLUE",$BJ34),"Cool","Warm"),IFERROR(IF(FIND("PURPLE",$BJ34),"Cool","Warm"),"Warm")))
I suppose 'Search' instead of 'Find' is optional if there is concern about being case-sensitive.
Hi,
I'm using the below formula to extract data (equipment number) with a hyphen. For example, cell contains:
V-1770A BLAST/PAINT EXTERNAL SURFACE (#17337C)
the formula:
=TRIM(MID(SUBSTITUTE(E3080," ",REPT(" ",99)),MAX(1,FIND("V-",SUBSTITUTE(E3080," ",REPT(" ",99)))-50),99))
returns the results:
V-1770A
The formula works great, but I have to change the FIND find_text parameter for each line.
Examples of various data lines:
I-1602 A/B "DRYER" DEMO SCAFFOLD # 2080 (#17324A)
E-1403 "IN/OUTLET VALVE " DEMO SCAFFOLD #2076 (#17324A)
C-1407 "INSPECTION WINDOWS" REPLACE METAL/SEALANT (#17324B)
T-1311C "ROOF TOP NOZZLES" CLEAN/PAINT (#17324C)
V-1770A BLAST/PAINT EXTERNAL SURFACE (#17337C)
No matter where the information is on the line the formula works, but I do not want to have to edit the formula each time the equipment letter changes.
I've tried using a Define Name table in the find_text parameter, but that does not work. Returns #VALUE.
Any suggestions or help would be greatly appreciated.
6601280012088
How do I extract the 7th number. =mid(C7,7,1)
if greater/equal to 7 - indicate "Male" otherwise "Female"
Hi,
I am trying to find a formula to yield the word to the left of the first space at the right. For example in the first item below, I would want the formula to result in BRAZR. The reason I cant work from the left (or at least I cant seem to) is there is a different number of spaces to get to the word to the left of the last space on the right as you can see below with the other examples. Could you please help me out with this??
XXX 5C-15 HZ BRAZR 3-14-47-14
XXX KARR 13-28-65-3
XXX HZ LEDUC-WB 16-9-49-25
XXX HZ BANTRY 4-21-19-13
Much appreciated.
I am trying to find a way to search a specific combination of letters in a list of words. For example, lets say I have a list of 100 words and I want to find all of the words that have exactly 1 A and 1 U in them and they don't have to be consecutive. Mutate, jaunt, magnum are examples that would meet my criterion. Does anyone know how to do this? Thanks.
Also, if possible I would like to be able "extract" (if that is the right term) those letters in alphabetical order into the cell to the right of the word. Eventually, I will sort the list of words and the extracted letters by the extracted letters to group the words that have the A and U.
Hello,
I believe you could use our Advanced Find & Replace add-in. On the first step you choose all your 100 rows and set the letter "A" as a search criterion. Then, you can:
1. either select all the found rows/columns/entries and run the new search over the selection with the letter "U" as a criterion OR
2. export the found entries to another workbook and run the search for the letter "u".
You can learn how the add-in works on its help page.
As for the second part of your task, I'm afraid you will need to use some kind of the VBA, but for that please ask around Mr. Excel forum.
Hope this helps!
POD CONTAINER SIZE TOTAL 40HQ reqirued result
KRPUS 40HQ x 1; 40GP x 10 ; =MID(B5,SEARCH("HQ",B5)+1,(SEARCH(";",A2)-SEARCH("HQ",B5))-1) 1
PKKHI 20GP x 1 ; 40HQ x 100 ; 40GP x 1 ; 100
USNYC 20GP x 1 ; 40HQ x 12 ; 40GP x 200 ; 12
Kindly assit me to correct above code
Hi How to use ISnumber and search formula to find couple of words from one text. Ex I am trying to find either "SHAW or "SHW" from this particular text "GL123456-Defee SR Heloc FR PCI LAND-SHAW"? I am using the formuls Is number(Search"SHAW",text")) and it returns with True or false result which is fine. But I want to embed word"SHW" too in the formula so I can find if the account is SHAW or SHW. How can I do that? I hope I am making sense and able to explain it.
Appreciate the help.
Thanks!!
Hi,can you help me,right function in how using "len" function
Hi, can you help me to find out "either" "or" condition in excel. also how to find probability from any data.
OK, I'm stuck.... somebody please help me out.
I have over 110 unique 7 digit values in Column B (50144815) and I need to see if/where in my spreadsheet they exist (in a different row in Column C).
Column C is 450 rows long and the unique 7 digit numbers would be hidden in a test string as exampled below:
"Retracement Survey of Alba, PID 50144815, Plan# 89584, unsigned digital copy, unsigned paper copy 53"
Vlookup works when it's only numbers comparing numbers, but when there is text and numbers together is seems to be choking up and not returning results.
Hello, Wesside,
you can try using VLOOKUP with wildcard characters (asterisk in particular). It enables searching for any sequence of characters within the cell.
Please take a look at these examples to learn how to level your formula up.
Another variant would be to use conditional formatting to highlight the row with the occurred values. And we have just a perfect tutorial for that either :)
Hope this info will be helpful!
Fabulous! I'll give it a try, was currently trying variations of "index and Match" functions
Ah, still having some trouble with this...
the * * trick doesn't seem to work using my limited knowledge of excel lol.
basically I want to compare column B (108 rows) to see where those number are in Column C (450 rows).
I had a "bit" of success but not much.
Then I tried this formula =vlookup('[Escrow108.xlsx]CBO Tab#2 - Other DNR'!$B$2:$B$109,O:O,1,FALSE)
I tried taking Column B and putting into another work sheet, then VLookup to compare column B on sheet 1 with column C on sheet 2, nope, even less success. The formula I used seems to stop searching at row 109 in column c...PLUS it isn't finding numbers in column c that I know exist in column b.
ASLO, i should note that in some cases, 3 rows of Column B might be listed in the text for 1 row of column C.
Hi, How to get the result for Search Function by selecting the range
Ex Search("Lucy",A1:A10)
Hi,
My data is like this:
Cell A: location (duplicate values)
Cell B: Revenue from those locations (positive and negative values)
Cell C: Month value
For a particular location (multiple values), I would like to get the value of the month when the revenue was greater than zero for the first time.
Can someone help me with this?
Thanks!
Hi, could you advise for my below sample?
Text sample 1: Creat highchart 4.0.418.02%91.98%-0.80%Fixed IncomeEquityOthersLoan010203
Text sample 2: Creat highchart 4.0.49.00%92.00%EquityReal Estate04020
I want to extract 2 text from each text sample above:
A. Start after 4.0.4 till the last %
B. Start from last % till before the first number show(the first number is always 0)
That is: "18.02%91.98%-0.80%" and "Fixed IncomeEquityOthersLoan" from text sample 1
"9.00%92.00%" and "EquityReal Estate" from text sample 2
The difficulty is the number of % occurrences is not fixed and the length of last number is not fixed. I'm thinking if there is a way to find position of the first % starting from right? I really got stuck here. Thanks for help in advance!
I have this formula =IF(ISNUMBER(SEARCH(D$1,L41&M41)),A41,"") every thing was perfect but than I found that this formula is searching some words from A1 that match in L41& M41 . example I only wanted XXX YYY ZZZ but it also displaying XXX only