Table of Contents
Presentation of function SEARCH
The function SEARCH allows you to find the position of a symbol into a string
The SEARCH function requires two parameters (and a third one optional)
- The first one is characters (or the sub-string) searched
- The second is the cell containing original string
- [Optional] The start position of your search.
=SEARCH(Character to find, String to look into, Position to start)
When use the function SEARCH
Presentation of the problem
Let's see how this function works in the following example
You want to extract the mobile numbers in the column A. The mobile numbers are in the string after the character "/".
As you can see on this picture, the position of the symbol "/" is not always on the same position . Sometimes it's because of the dialing code, sometimes because there is spaces.
So the important thing is to locate the position of the character "/" in the cell in order to extract all the characters on the left of it.
Find the position
Position of the symbol "/" is given by this formula.
So for the first phone number, the first "/" is in 9th position in the string
Extract the first phone number
As we want to extract the first mobile number (with area code) we will use the LEFT function and the formula in column C is
Extract the position of the mobile number
The mobile number is after the string "cell:". So know, we are going to write a new SEARCH function with this specific string
As you can see, for the last string, there is an error. This error occurs when the string is not found.
Use the function IFERROR
To avoid to return an error, we can use the wonderful function IFERROR
=IFERROR(formula, result in case of error)
So here, we can simply write
Extract the mobile phone
Watch out! The position returns by the function is the position of the first character, not the last one.
So we must add to the result of the function the value 5. The string "cell:" as 5 characters
To extract the last phone number, we will write the following formula