In this guide, you’ll see how to use the Excel string functions to retrieve specific characters from a string in Excel.
Specifically, you’ll observe how to apply the following Excel string functions using practical examples:
Excel String Functions Used | Description of Operation |
LEFT | Get characters from the left side of a string |
RIGHT | Get characters from the right side of a string |
MID | Get characters from the middle of a string |
LEFT, FIND | Get all characters before a symbol |
LEFT, FIND | Get all characters before a space |
RIGHT, LEN, FIND | Get all characters after a symbol |
MID, FIND | Get all characters between two symbols |
Excel String Functions
To start, suppose that you stored different strings in Excel that contain a mixture of:
- Letters
- Digits
- Symbols
- Spaces
The ultimate goal is to isolate/retrieve only the digits within those strings.
Retrieve a specific number of characters from the left side of a string
In the example below, you’ll see 3 strings. Your goal is to retrieve only the 5 digits from the left-side:
(1) First, type/paste the table below into Excel, within the range of cells A1 to B4:
Identifier | Result |
55555-End | |
77777-End | |
99999-End |
Since the goal is to retrieve the first 5 digits from the left, you’ll need to use the LEFT formula, which has the following structure:
=LEFT(Cell where the string is located, Number of characters needed FROM THE LEFT)
(2) Next, type the following formula in cell B2:
=LEFT(A2,5)
(3) Finally, drag the LEFT formula from cell B2 to B4 in order to get the results across your 3 records.
This is how your table would look like in Excel after applying the LEFT formula:
Identifier | Result |
55555-End | 55555 |
77777-End | 77777 |
99999-End | 99999 |
Retrieve a specific number of characters from the right side of a string
To retrieve the 5 digits from the right-side of the strings:
(1) Type/paste the following table into cells A1 to B4:
Identifier | Result |
ID-55555 | |
ID-77777 | |
ID-99999 |
Here, use the RIGHT formula that has the following structure:
=RIGHT(Cell where the string is located, Number of characters needed FROM THE RIGHT)
(2) Then, type the following formula in cell B2:
=RIGHT(A2,5)
(3) Finally, drag your RIGHT formula from cell B2 to B4.
This is how the table would look like after applying the RIGHT formula:
Identifier | Result |
ID-55555 | 55555 |
ID-77777 | 77777 |
ID-99999 | 99999 |
Get a specific number of characters from the middle of a string
To retrieve the 5 digits from the middle of the strings:
(1) Type/paste the following table into cells A1 to B4:
Identifier | Result |
ID-55555-End | |
ID-77777-End | |
ID-99999-End |
Here, use the MID formula with the following structure:
=MID(Cell of string, Start position of first character needed, Number of characters needed)
(2) Now type the following formula in cell B2:
=MID(A2,4,5)
(3) Finally, drag the MID formula from cell B2 to B4.
This is how the table would look like:
Identifier | Result |
ID-55555-End | 55555 |
ID-77777-End | 77777 |
ID-99999-End | 99999 |
Gel all characters before a symbol (for varying-length strings)
To retrieve all the desired digits before a symbol (e.g., the hyphen symbol “-“) for varying-length strings:
(1) First, type/paste the following table into cells A1 to B4:
Identifier | Result |
111-IDAA | |
2222222-IDB | |
33-IDCCC |
Here, you’ll need to use the FIND function to find your symbol:
=FIND(the symbol in quotations that you'd like to find, the cell of the string)
(2) Then, type the following formula in cell B2:
=LEFT(A2,FIND("-",A2)-1)
Note that the “-1” at the end of the formula simply drops the hyphen symbol from the final results.
(3) As before, drag your formula from cell B2 to B4 to see the complete results:
Identifier | Result |
111-IDAA | 111 |
2222222-IDB | 2222222 |
33-IDCCC | 33 |
Gel all characters before a space (for varying-length strings)
To get all the digits before a space for varying-length strings:
(1) To start, type/paste the following table into cells A1 to B4:
Identifier | Result |
111 IDAA | |
2222222 IDB | |
33 IDCCC |
(2) Then, type the following formula in cell B2 (here, simply leave an empty space within the double quotes):
=LEFT(A2,FIND(" ",A2)-1)
(3) Finally, drag the formula from cell B2 to B4:
Identifier | Result |
111 IDAA | 111 |
2222222 IDB | 2222222 |
33 IDCCC | 33 |
Obtain all characters after a symbol (for varying-length strings)
To get all the digits after the hyphen symbol (“-“) for varying-length strings:
(1) First, type/paste the following table into cells A1 to B4:
Identifier | Result |
IDAA-111 | |
IDB-2222222 | |
IDCCC-33 |
(2) Secondly, type the following formula in cell B2:
=RIGHT(A2,LEN(A2)-FIND("-",A2))
(3) Finally, drag your formula from cell B2 to B4:
Identifier | Result |
IDAA-111 | 111 |
IDB-2222222 | 2222222 |
IDCCC-33 | 33 |
Obtain all characters between two symbols (for varying-length strings)
To retrieve only the digits between the two hyphen symbols for varying-length strings:
(1) First, type/paste the following table into cells A1 to B4:
Identifier | Result |
IDAA-111-AA | |
IDB-2222222-B | |
IDCCC-33-CCC |
(2) Then, type the following formula in cell B2:
=MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1)
(3) And finally, drag your formula from cell B2 to B4:
Identifier | Result |
IDAA-111-AA | 111 |
IDB-2222222-B | 2222222 |
IDCCC-33-CCC | 33 |