Extracting numbers from at end of a string

rplohocky

Active Member
Joined
Sep 25, 2005
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am trying to find a formula that will extract the numbers at the end of a string. Sometimes the numbers will be 1, 2, 3, 4 or more. I tried using this formula but it returns B6 118, when I want just 118.
This is what I using in column B:
Example: 12 Count--CAB6 118
My formula:
Excel Formula:
=RIGHT(B3,SUM(LEN(B3)-LEN(SUBSTITUTE(B3,{"0","1","2","3","4","5","6","7","8","9"},""))))
My return is: B6 118
I think I need to add something to the formula that will take the numbers after the last space.

Thank you.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Here is one idea...
Book1
AB
112 Count--CAB6 118118
241 42 Count- - CAB 6 12341234
Sheet4
Cell Formulas
RangeFormula
B1:B2B1=IF(ISERROR(FIND(" ",A1)),A1,RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))

If you want the extracted "number" to actually be treated as a number rather than text, then add a 0 to the formula...
Excel Formula:
=0+IF(ISERROR(FIND(" ",A1)),A1,RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1," ","~",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))
 
Upvote 0
This formula should work for up to a 10-digit number in your version of Excel 365...
Excel Formula:
=MAX(IFERROR(0+RIGHT(B3,11-SEQUENCE(10)),))
 
Last edited:
Upvote 0
Sometimes the numbers will be 1, 2, 3, 4 or more.

I think I need to add something to the formula that will take the numbers after the last space.

Here are two other options that should do that. I have included the second one as you may not yet have the TEXTAFTER function.

22 07 04.xlsm
BCD
312 Count--CAB6 118118118
441 42 Count- - CAB 6 123412341234
5ABC 123456781234567812345678
End number
Cell Formulas
RangeFormula
C3:C5C3=TEXTAFTER(B3," ",-1)+0
D3:D5D3=RIGHT(SUBSTITUTE(B3," ",REPT(" ",20)),20)+0
 
Upvote 0
Another option,

In C3, formula copied down :

=-LOOKUP(1,-RIGHT(B3,ROW($1:$99)))
 
Upvote 0
This formula should work for up to a 10-digit number in your version of Excel 365...
Excel Formula:
=MAX(IFERROR(0+RIGHT(B3,11-SEQUENCE(10)),))
Thank you for all the help! All of these options worked great. I ended up using Rick's only because it was shorter. Thanks Rick!
 
Upvote 0
I ended up using Rick's only because it was shorter.
Just be aware that does not specifically extract the number after the last space.
I don't know what is possible with your data, but it would produce incorrect results with, for example, these values
12 Count--CDEC 11
12 Count--CAB6 1.18
 
Upvote 0
Just be aware that does not specifically extract the number after the last space.
I don't know what is possible with your data, but it would produce incorrect results with, for example, these values
12 Count--CDEC 11
12 Count--CAB6 1.18
Peter_SSs,
I assume Ricks formula would provide an accurate result if my numbers never changed the format such as no decimals or spaces???
 
Upvote 0
.. no decimals or spaces???
I'm not sure that I understand. Your original post asked for the number after the last space. Are you now suggesting there are no spaces?

It would be good if we could have (preferably with XL2BB ) a sample of 8-10 examples of your data showing any variety that can occur with your data and the expected results. It is always difficult to give a robust but efficient suggestion for something where there is only one example.
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,393
Members
449,222
Latest member
taner zz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top