The tutorial shows how to extract number from various text strings in Excel by using formulas and the Extract tool.
When it comes to extracting part of a text string of a given length, Excel provides three Substring functions (Left, Right and Mid) to quickly handle the task. When it comes to extracting numbers from an alphanumeric string, Microsoft Excel provides… nothing.
To get a number from a string in Excel, it takes a little ingenuity, a bit of patience, and a bunch of different functions nested into each other. Or, you can run the Extract tool and have the job done with a mouse click. Below you will find full details on both methods.
How to extract number from the end of text string
When you have a column of alphanumeric strings where number comes after text, you can use the following formula to get it.
We will dwell on the formula's logic a bit later. For now, simply replace cell with a reference to the cell containing the original string (A2 in our case), and enter the formula in any empty cell in the same row, say in B2:
=RIGHT(A2, LEN(A2) - MAX(IF(ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1) *1)=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0)))
This formula gets number only from the end. If a string also has numbers in the beginning or middle, they are ignored:
The extraction is performed with the RIGHT function that belongs to the category of Text functions. The output of this function is always text. In our case, the result is a numeric substring, which in terms of Excel is also text, not number.
If you need the result to be a number (that you can use in further calculations), then wrap the formula into the VALUE function or perform an arithmetic operation that does not change the result, say, multiply by 1 or add 0. To catch errors in the strings that do not contain a single number, use the IFERROR function. For example:
=IFERROR(VALUE(RIGHT(A2, LEN(A2) - MAX(IF(ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1)*1)=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0)))), "")
or
=IFERROR(RIGHT(A2, LEN(A2) - MAX(IF(ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1) *1)=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0))) +0, "")
Note. In Dynamic Array Excel (Office 365 and 2021), you enter the formula in the usual way with the Enter key. In Excel 2019 and earlier, it only works as an array formula, so remember to press Ctrl + Shift + Enter to complete it.
How this formula works:
To extract number from an alphanumeric string, the first thing you need to know is where to start the extraction. The position of the last non-numeric character in a string is determined with the help of this tricky formula:
MAX(IF(ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1)*1)=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0))
To understand the logic, let's investigate it from the inside:
The ROW(INDIRECT("1:"&LEN(A2))) combination creates a sequence of numbers corresponding to the total of characters in the source string (A2), and we serve these sequential numbers to MID as the starting numbers:
MID(A2, {1;2;3;4;5;6;7;8}, 1)
The MID function pulls each individual character from A2 and returns them as an array:
{"0";"5";"-";"E";"C";"-";"0";"1"}
As MID is a text function, its output is always text (as you can notice, all the characters are enclosed in quotation marks). To turn numeric ones into numbers, we multiply the array by 1 (double negation --MID() will have the same effect). The result of this operation is an array of numbers and #VALUE! errors representing non-numeric characters:
ISNUMBER({0;5;#VALUE!;#VALUE!;#VALUE!;#VALUE!;0;1})
The ISNUMBER function evaluates each element of the array and gives its verdict in the form of Boolean values - TRUE for numbers, FALSE for anything else:
{TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE}
This array goes to the logical test of the IF function, where each element of the array is compared against FALSE:
IF({TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE}=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0)
For each FALSE (non-numeric value), another ROW(INDIRECT()) function returns its relative position in the string. For each TRUE (numeric value), a zero is returned. The resulting array looks as follows:
{0;0;3;4;5;6;0;0}
The rest is easy. The MAX function finds the highest number in the above array, which is the position of the last non-numeric value in the string (6 in our case). Simply, subtract that position from the total length of the string returned by LEN, and pass the result to RIGHT to let it know how many characters to extract from the right side of the string:
RIGHT(A2, LEN(A2) - 6)
Done!
How to extract number from the beginning of text string
If you are working with records where text appears after number, you can extract number from the start of a string by using this generic formula:
With the original string in A2, use the following formula to get number:
=LEFT(A2, MATCH(FALSE, ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2)+1)), 1) *1), 0) -1)
No matter how many digits are in the middle or end, only the starting number is extracted:
Note. In Excel 365 and Excel 2021, due to support for dynamic arrays, a regular formula works fine. In Excel 2019 and earlier, you should press Ctrl + Shift + Enter to explicitly make it an array formula.
How this formula works:
Here, we again use the combination of ROW, INDIRECT and LEN functions to create a sequence of numbers equal to the total of characters in the source string plus 1 (the role of that additional character will become clear a bit later).
ROW(INDIRECT("1:"&LEN(A2)+1))
MID and ISNUMBER do the same job as in the previous example - MID pulls individual characters and ISNUMBER converts them to the logical values. The resulting array of TRUE's and FALSE's goes to the MATCH function as a lookup array:
MATCH(FALSE, {TRUE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;FALSE}, 0)
MATCH computes a relative position of the first FALSE, giving us the position of the first non-numeric character in the string (3 in A2). To extract the preceding numbers, we subtract 1 from position the first text character and serve the difference to the num_chars argument of the LEFT function:
LEFT(A2, 3-1)
Now, back to an "extra" character in the sequence generated by ROW(INDIRECT()+1)). As you already know, this sequence provides the starting points for the MID function. Without +1, MID would extract exactly as many characters as there are in the original string. If the string contains only numbers, ISNUMBER will return only TRUE's while MATCH needs at least one FALSE. To ensure that, we add one more character to the total length of the string, which the MID function would convert to an empty string. For example, in B7, MID returns this array:
{"1";"2";"3";"4";""}
Note. As is the case with the RIGHT function, LEFT also returns a numeric substring, which is technically text, not number. To get the result as a number rather than a numeric string, nest the formula in the VALUE function or multiply the result by 1 as shown in the first example.
How to get number from any position in a string
If your task implies extracting number from anywhere in a string, you can make use of the following mind-boggling formula published on MrExcel forum:
=SUMPRODUCT(MID(0&A2, LARGE(INDEX(ISNUMBER(--MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1)) * ROW(INDIRECT("1:"&LEN(A2))), 0), ROW(INDIRECT("1:"&LEN(A2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A2)))/10)
Where A2 is the original text string.
Breaking down this formula would require a separate article, so you can simply copy it to your worksheet to make sure it really works :)
Upon examining the results, however, you may notice one insignificant drawback - if the source string does not contain a number, the formula returns zero, as in row 6 in the screenshot above. To fix this, you can wrap the formula in the IF statement, the logical test of which checks if the source string contains any number. If it does, the formula extracts the number, otherwise returns an empty string:
=IF(SUM(LEN(A2)-LEN(SUBSTITUTE(A2, {"0","1","2","3","4","5","6","7","8","9"}, "")))>0, SUMPRODUCT(MID(0&A2, LARGE(INDEX(ISNUMBER(--MID(A2,ROW(INDIRECT("$1:$"&LEN(A2))),1))* ROW(INDIRECT("$1:$"&LEN(A2))),0), ROW(INDIRECT("$1:$"&LEN(A2))))+1,1) * 10^ROW(INDIRECT("$1:$"&LEN(A2)))/10),"")
As shown in the screenshot below, the improved formula works beautifully (kudos to Alex, our Excel guru, for this improvement):
Unlike in all previous examples, the result of this formula is number. To make sure of this, just notice the right-aligned values in column B and truncated leading zeros.
Tip. In Excel 365 - Excel 2019, there is a much simpler solution with the help of the TEXTJOIN function. Please see How to remove text and keep numbers.
Extract number from text string with Ultimate Suite
As you have just seen, there is no trivial Excel formula to pull number from a text string. If you have difficulties with understanding the formulas or tweaking them for your data sets, you may like this simple way to get number from string in Excel.
With our Ultimate Suite added to your Excel ribbon, this is how you can quickly retrieve number from any alphanumeric string:
- Go to the Ablebits Data tab > Text group, and click Extract:
- Select all cells with the source strings.
- On the Extract tool's pane, select the Extract numbers radio button.
- Depending on whether you want the results to be formulas or values, select the Insert as formula box or leave it unselected (default).
My advice is to select this box if you want the extracted numbers to update automatically as soon as any changes are made to the source strings. If you want the results to be independent on the original strings (e.g. in case you plan to remove the source data at a later point), then do not select this box.
- Click the Insert Results button. Done!
Like in the previous example, the results of the extraction are numbers, meaning you are free to count, sum, average, or perform any other calculations with them.
In this example, we've chosen to insert the results as values, and the add-in did exactly what was asked for:
If the Insert as formula checkbox was selected, you'd observe a formula in the formula bar. Curious to know which one? Just download Ultimate Suite's trial and see for yourself :)
Available downloads
Excel Extract Number - sample workbook (.xlsx file)
Ultimate Suite - trial version (.exe file)
565 comments
Good day,
what formula will work best, if you want to create a register list. That when you type an employee's pers number all the personal info pulls through eg. name, surname, job title and workplace. I have the master data sheet but want to make my life easier when reporting on other related reports.
Hi, I used the formula to extract number from beginning of strings :
=LEFT(A2,SUM(LEN(A2)-LEN(SUBSTITUTE(A2,{"0","1","2","3","4","5","6","7","8","9"},""))))
to extract
2A 1234521
it was supposed to extract 2, but instead it extract
2A 12345
Why is that? Please help.
Hi Shay,
To extract a number only from the beginning, please use this formula:
=LEFT(A2, MATCH(FALSE, ISNUMBER(MID(A2, ROW(INDIRECT( "1:"&LEN(A2)+1)), 1) *1), 0) -1)
Hello
I would like to extract only those number which has tin written in front. can someone help me with formula.
Goodman Fielder tin500766109 FOODMEA072 Chicken Thighs Normal (CTN/7.5KG)
Foods Pacific Ltd tin 500546606 FOODDAI074 Cheese Mozzarella Grated 5 Star Gold (CTN/ 2x5KG)
Tappoo tin500618105 BEVCIDER004 Cider Pear Isaac's (CTN/ 12x330ml)
Tappoo tin500618105 BEVCIDER005 Cider Apple Isaac's (CTN/ 12x330ml)
Satish Kumar Marketing tin 113065604 FOODVEG074 VegAlfalfa Sprout Imported (Punnet)
Hello Reader, just another comment . . .
But need you + any assistants, to know VERY VERY sincere appreciation for such brilliant compilation of commitment to others having a success using sheets, over many years ! !
I only started when PC’s were 16K / 64K we could do 255 x 255 single sheets . . . Oh, how it’s changed.
THANKYOU & hopefully your future plans for site develop how you wish.
Best Regards,
Lee_ an Aussie
ps. ;-)
Hello,
I would like to extract the phone numbers from this cell.
7. UZOUKWU, PRINCE ROYCE 0803 743 5119-MUM/0803 275 9140-DAD
I have a long spreadsheet of names & the positioning of the phone numbers are not in the same place.
However I will separate these phone numbers in 2 cells.
Hello!
If the phone number always has the same number of digits, you can try these formulas:
=MID(A1,SEARCH("-",A1,1)-13,13)
=MID(A1,SEARCH("-",A1,SEARCH("-",A1,1)+1)-13,13)
I hope I answered your question. If something is still unclear, please feel free to ask.
The first one worked, for the first phone numbers and the 2nd pulled the 2nd phone number.
Thank you so much.
Hi alexander,
How do i extract number from
1 - 123, Singh Petrol Pump, Bishrampur, 497226, 36
2 - Company, 123, 123, 788031, 123
3 - 234, Danapur Maruti Suzuki Agency, Gopalganj, 841427, Bihar
4 - Plot No RM-126,R & C Zone,, MIDC INDL. Area, Butibori. Dist Nagpur, 441122, 27- Maharashtra
FOR 1ST ROW I WANT 497226
FOR 2ND ROW I WANT 788031
FOR 3RD ROW I WANT 841427
FOR 4TH ROW I WANT 441122
Please let me know the formula
Hello!
You are using commas as word separators. You can extract the penultimate word using the formula —
=TRIM(MID(A1,FIND("*",SUBSTITUTE(A1,",","*",LEN(A1)-1 -LEN(SUBSTITUTE(A1,",",""))),1)+1, FIND("*",SUBSTITUTE(A1,",","*",LEN(A1)- LEN(SUBSTITUTE(A1,",",""))),1)- FIND("*",SUBSTITUTE(A1,",","*",LEN(A1)-1 -LEN(SUBSTITUTE(A1,",",""))),1)-1))
Hope this is what you need.
Thank you Alexander
what if i want to get only 4 digit for example :
aadfnmm kadflk ZZ56 ladkkfiiss
alkliid kalkem 23 lsd 5675 llk,slkdk
thanks you
ILH-E-AC-030
ILH-E-AC-031
ILH-E-AC-032
ILH-E-AC-033
ILH-E-LO-003 SHT1
ILH-E-LO-003 SHT2
ILH-E-LO-027 SHT1
ILH-E-LO-027 SHT2
ILH-E-LO-027 SHT3
i want to extract this to other cell so it look like:
030
031
032
033
033
033
027
027
027
can someone tell me the formula to extract just the 3 digits number after the last "-" from left?
Hello!
I hope you have studied the recommendations in the tutorial above. It contains answers to your question.
I am trying to pull just $ amount with Decimals and commas in this sentence how would I do that
Paying total amount of $ 12,275.21
Thanks in advance
Thank you, it's works!
Working Fine.
=CONCAT(IF(ISNUMBER(--MID(A4,ROW($1:$93),1)),MID(A4,ROW($1:$93),1),""))
Using the formula
1orrange&2apple = 12 ( Answer getting now)
I need the answer as
1orrange&2apple = 3 ( it suppose to add up the numbers)
This Formula is working out for me. But is there any solution that I can sumup the values.
Example: 1apple&2orange = 12 (The answer what I am getting as of now but I need to sumup & get "3" as a answer)
Please help me with this.
=IF(SUM(LEN(A2)-LEN(SUBSTITUTE(A2, {"0","1","2","3","4","5","6","7","8","9"}, "")))>0, SUMPRODUCT(MID(0&A2, LARGE(INDEX(ISNUMBER(--MID(A2,ROW(INDIRECT("$1:$"&LEN(A2))),1))* ROW(INDIRECT("$1:$"&LEN(A2))),0), ROW(INDIRECT("$1:$"&LEN(A2))))+1,1) * 10^ROW(INDIRECT("$1:$"&LEN(A2)))/10),"")
Hello!
To extract all numbers from text please use the following formula
=CONCAT(IF(ISNUMBER(--MID(A4,ROW($1:$93),1)),MID(A4,ROW($1:$93),1),""))
Working Fine.
=CONCAT(IF(ISNUMBER(--MID(A4,ROW($1:$93),1)),MID(A4,ROW($1:$93),1),""))
Using the formula
1orrange&2apple = 12 ( Answer getting now)
I need the answer as
1orrange&2apple = 3 ( it suppose to add up the numbers)
Hello!
Replace CONCAT function with SUM:
=SUM((IF(ISNUMBER(--MID(A4,ROW($1:$93),1)),--MID(A4,ROW($1:$93),1),"")))
Hope this is what you need.
500-555-0172
325-555-0137
582-555-0148
1 (21) 500 555-0145
1 (12) 500 555-0117
615-555-0153
926-555-0182
1 (22) 500 555-0140
1 (11) 500 555-0190
961-555-0122
740-555-0182
775-555-0164
Write a formula to extract the numbers, eliminating all the spaces symbols state codes
Hello!
Formula to extract the numbers, eliminating all the spaces symbols and codes —
=CONCAT(IF(ISNUMBER(--MID(REPLACE(A2,1,IFERROR(FIND(")",A2,1),1),""), ROW($1:$93),1)), MID(REPLACE(A2,1,IFERROR(FIND(")",A2,1),1),""), ROW($1:$93),1),""))
I hope my advice will help you solve your task.
Please could you help me with a formula that can extract number from 9 year(s), 11 month(s),
and add a decimal point after years.
Q1- 9 year(s), 11 month(s),
Answer from formula - 9.11
Hello!
The formula below will do the trick for you:
=SUBSTITUTE(TRIM(CONCAT(IF(ISNUMBER(--MID(Q1,ROW($1:$93),1)),MID(Q1,ROW($1:$93),1)," ")))," ",".")
I hope it’ll be helpful.
Dear Expert Users
Please help anybody for get area from 250x350 that is written in one cell
and area should be 87500.
Hello!
Unfortunately, you can only turn text into a formula in Excel using macros. This cannot be done using formulas.
this is the number 15060277631602300000,
i want to separate it like that 1506027763//1602300000
whats the formula for this .please help
Sorry but,
35600aaa bbb/ccc/25*36/450 // Original text.
35600 (O) // The answer I want.
35600aaa bbb(X) // When applying the provided formula.
Can you make an extended formula that meets my requirements?
Sorry but,
I want
25600aaa BBB / 25 * 35 * 46cm
->
25600
I have read well on how to extract numbers from the beginning of a text string.
However, even if there are additional numbers in the middle of the text string, I want to extract only the characters at the beginning in addition to the additional numbers. In other words, if you have a number in the middle of a text string (if the number ends and there is another number after the letter), you want the result to remain unchanged, but the formula provided does not. Is there a possible formula?
Like below
25600aaa bbb/25*35*46cm
Do you have formula, including the decimal point.
Sample: RT-12.5BT, RG5.7T
Because when I use the formula result is
Result: 125, 57
Hello James!
I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail?
Which formula are you using? Explain more precisely what result you want to get? Number with two decimal places?
Hi alexander,
How do i extract number from 113°53'42" to 1135342 ?
Please let me know the formula
Thanks before.
Hello,
Please try the following formula:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B1,"”",""),"°",""),"’","")
I hope this will help