Pulling the number from the text (Part 2)

smalik

Board Regular
Joined
Oct 26, 2006
Messages
180
Office Version
  1. 365
Platform
  1. Windows
Recently, I asked the following question:

How to pull the number from the following statements:
4+ years of experience ....
10+ years of experience ....

This was the example when the number was at the beginning of the text.

The following formula worked perfectly fine
=LEFT(A1,FIND("+",A1)-1)

Although majority of the cells have the number at the beginning, I am finding that the number could be in the middle of the string as well. How do I modify this formula so that I can capture the number irrespective of where it is. The number always comes with a + sign, e.g., 5+ or 10+

Any help is greatly appreciated.

Thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Is there only 1 number in the string? Here's one way but it uses INDIRECT.

Book3
AB
15+ years of experience5
210+ years of experience10
3Experience of 15+ years15
Sheet2
Cell Formulas
RangeFormula
B1:B3B1=1*TEXTJOIN("",TRUE,IFERROR((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)*1),""))
 
Upvote 0
In fooling around w/this I also found that a large percent of the time FLASH FILL works, too.
 
Upvote 0
One more

Excel Formula:
=TRIM(MID(" "&A1,SEARCH("+"," "&A1)-2,2))+0
 
Upvote 0
Is there only 1 number in the string? Here's one way but it uses INDIRECT.
But it could use SEQUENCE instead of INDIRECT, and CONCAT would make more sense than TEXTJOIN with "" as the delimiter. :)
Excel Formula:
=CONCAT(IFERROR(MID(A1,SEQUENCE(LEN(A1)),1)+0,""))+0

One more

Excel Formula:
=TRIM(MID(" "&A1,SEARCH("+"," "&A1)-2,2))+0
As I am sure you are aware, this limits the number to a maximum of two digits - which looks like it could be the case if they are all "years of experience".
TRIM would not be required though, and one of the " "& can be eliminated
FIND would suffice here too.
Excel Formula:
=MID(" "&A1,FIND("+",A1)-1,2)+0

Another option in case the number could be longer than 2 digits and/or contain decimals is shown in column B below.
Also, if you happen to have the TEXTAFTER function (not many will have it yet, but it is coming), column C offers a simpler alternative.

22 03 26.xlsm
ABC
15+ years of experience55
210+ years of experience1010
3Experiences of 15+ years1515
4Experiences of 7+ years77
5Experiences of 1.5+ years1.51.5
6Combined experience of 103+ years103103
Get Num
Cell Formulas
RangeFormula
B1:B6B1=RIGHT(SUBSTITUTE(LEFT(A1,FIND("+",A1)-1)," ",REPT(" ",20)),20)+0
C1:C6C1=TEXTAFTER(LEFT(" "&A1,FIND("+",A1))," ",-1)+0
 
Upvote 0
Solution
Thanks everyone @Peter_SSs, @JEC, @kweaver, for helping me with this formula. This is an amazing group.

I tried all the options. Here is what I came up with.
  • For some reason my Excel version did not recognize "Textafter' command. I received #NAME? error
  • =RIGHT(SUBSTITUTE(LEFT(A1,FIND("+",A1)-1)," ",REPT(" ",20)),20)+0 -- This formula worked with all entries in my dataset
  • =TRIM(MID(" "&A6,SEARCH("+"," "&A6)-2,2))+0 and =MID(" "&A6,FIND("+",A6)-1,2)+0 -- These two formulas gave me 0.5 as a result with "1.5+ years"
  • =CONCAT(IFERROR(MID(A6,SEQUENCE(LEN(A6)),1)+0,""))+0 and =1*TEXTJOIN("",TRUE,IFERROR((MID(A6,ROW(INDIRECT("1:"&LEN(A6))),1)*1),"")) -- These two formulas gave me 15 as a result with "1.5+ years"

PS: I am using "Microsoft® Excel® for Microsoft 365 MSO (Version 2202 Build 16.0.14931.20128) 64-bit "
 
Upvote 0
Thanks everyone
You're welcome. :)

For some reason my Excel version did not recognize "Textafter' command. I received #NAME? error
That is not surprising as TEXTAFTER is a very new function & m/soft is just rolling it out to a small number of subscribers at a time.

In relation to some suggestions not working with numbers like 1.5, it is important to use your sample data to show what variety might be in your real data since we have no idea unless you do that. ;)
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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