How to extract number is a string of text?

wkirkcrawford

Board Regular
Joined
Dec 7, 2013
Messages
72
Greetings,

This is my string; LANTUS 24 Units in the Morning, 18 Units + HUMLOG at Dinner Time.

I need to extract the numbers, 24 and 18.

I've seen all kinds of answers, including VBA, which isn't for me.

W. Kirk Crawford
Tularosa, New Mexico
 
Jtakw,

You are using two other cells. I can't use that. Oh yes, I know, I could use it in some hidden cells, but I don't want that.

You also assumed I was going to put that info into other columns.

I just want to extract each number in different cells.

W. Kirk Crawford
Tularosa, New Mexico
Your explanation is contradictory and confusing.
Please provide sample data/text string With expected results, in the way you have the data layout in your sheet(s).
 
Last edited:
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Your explanation is contradictory and confusing.
Please provide sample data/text string With expected results, in the way you have the data layout in your sheet(s).
Jtakw,

The string of text is, as of now, LANTUS 24 Units in the Morning, 18 Units + Humlog at Dinner Time.

The names will change and the number isn't always 2 digits.

All I want for it to return is either 24 or 18.

The results will be just elsewhere throughout my headers.

I want to change the numbers in just one location and it would appear everywhere I have it.

I hope this explains everything. Wait, I'm thinking I could cell outside of my sheet. I'm thinking about that. I would have to remember where that location is. I'm thinking.

W. Kirk Crawford
Tularosa, New Mexico
 
Upvote 0
If you used XL2BB with examples, we would be able to try to find a solution.
 
Upvote 0
Hi,

Assuming you want the numbers extracted to separate columns, and "Units" always immediately following the numbers, drag formula as far across columns as necessary.

Book3.xlsx
ABCDE
1LANTUS 24 Units in the Morning, 18 Units + HUMLOG at Dinner Time.2418  
2LANTUS 224 Units in the Morning, 18888 Units + HUMLOG at Dinner Time, 2 Units COOKIES before bed.224188882 
Sheet722
Cell Formulas
RangeFormula
B1:E2B1=IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A1,"Units",REPT(" ",255),COLUMNS($B1:B1)),255))," ",REPT(" ",255)),99)+0,"")
Jtakw,

OK, I got the first part to work, but with this change. =IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($AK1,"Units",REPT(" ",255),COLUMNS($av104)),255))," ",REPT(" ",255)),99)+0,"")
Which returns 24, which is just what I wanted.

But I was unable to extract the 18 to a different cell. I don't need COLUMNS. Also, I do not understand the ',255' part.

Maybe I'm asking for too much.

I plan to use that results, 24 and 18 in many different locations.

What if I use this string, 24 Morning / 18 Din.+ Humlog ? This might be easier.

I have learned over the years to have a given in one place and then reference that location to get that given data over and over again. I hope that made my thoughts clear.

Thanks for all of your help. I'm amazed.

W. Kirk Crawford
Tularosa, New Mexico
 
Upvote 0
Ok, I think (more like guess, since you still haven't given details on your setup and goal) I know what you're trying to do now.
First of all, don't get confused about the COLUMNS function in the formula, it really doesn't have anything to do with Columns, it's a way for the formula to Count which number within the string to extract,
(e.g. 1,2,3 - first, second, 3rd, etc...)

Now I'm assuming you'll be putting the formula(s) in various cell locations with no particular relation to the Cell with the original Text string.
So, use below updated formula, REPLACE the Cell reference to point to your original text string Cell (e.g. $AK$1, make sure you use Absolute referencing, Note the $ symbols)
To extract the 1st number, use 1 in the formula, to extract the 2nd number, change the 1 to 2, for 3rd number change the 1 to 3, etc.

This is based on the text string in OP:

Book3.xlsx
ABCD
9LANTUS 24 Units in the Morning, 18 Units + HUMLOG at Dinner Time.24
1018
Sheet722
Cell Formulas
RangeFormula
B9B9=IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$9,"Units",REPT(" ",255),1),255))," ",REPT(" ",255)),99)+0,"")
D10D10=IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$9,"Units",REPT(" ",255),2),255))," ",REPT(" ",255)),99)+0,"")
 
Upvote 0
Solution
Too late to edit.

Also want to point out, once you have the formula(s) in place at your desired cell(s), you can then, if you choose, refer to Those cells for the numbers:

Book3.xlsx
ABCD
9LANTUS 24 Units in the Morning, 18 Units + HUMLOG at Dinner Time.24
1018
11
12
1324
1418
Sheet722
Cell Formulas
RangeFormula
B9B9=IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$9,"Units",REPT(" ",255),1),255))," ",REPT(" ",255)),99)+0,"")
D10D10=IFERROR(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$9,"Units",REPT(" ",255),2),255))," ",REPT(" ",255)),99)+0,"")
C13C13=B9
B14B14=D10
 
Upvote 0
You're very welcome, I'm glad we got it worked out for you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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