Extract Numbers from string

nubranger

Board Regular
Joined
Dec 23, 2019
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Hi

I have the following samples where I need to extract just the numbers and convert them to years. I was able to accomplish this but by using Indirect which makes my spreadsheet very slow. I need a formula that is not volatile. Also no macro.

ACCT Y/E JUL 20
ACCT YE MAR 18*
FY2019 China AOS IQAR

I have no issue with the first sample. I just use this:

Rich (BB code):
=CONCAT("20",MID(A122,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A122&"0123456789")),LEN(A122)))
>>> and this would return 2020 which what I wanted.

But I'm having issues with the 2nd and 3rd samples. The second sample would return 18* and the last one would return 2019 China AOS IQAR. So basically it returns the number plus all text after the last numeric from the string. I tried IF with ISNUMBER or IF >2000 (since all years to be extract would be 2018+) but none work since the returned values are not numbers.

Thanks for the help.
 
As long as you will never insert any rows before or within the data (otherwise a different, longer formula would be needed), this array-entered** formula would work...

=20&MID(A1,MAX(IF(ISNUMBER(0+MID(A1,ROW($1:$99),1)),ROW($1:$99)))-1,2)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
As long as you will never insert any rows before or within the data (otherwise a different, longer formula would be needed), this array-entered** formula would work...

=20&MID(A1,MAX(IF(ISNUMBER(0+MID(A1,ROW($1:$99),1)),ROW($1:$99)))-1,2)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.


Hi Rick. Works like a charm. How about if I have this entry also:

services for financial year ended 31 December 2018

It returns 2031.

EDIT: I think it works now. I just need to change the Row($1:$99) to the number of rows I use.

Thanks
 
Upvote 0
@lrobbo314
based on post#10
Year = Table.SelectColumns(Table.TransformColumnTypes(Table.AddColumn(Source, "Year", each "20"&Text.End(Text.Select([raw],{"0".."9"}),2)),{{"Year", Int64.Type}}),{"Year"})
what do you think? ;)
year.jpg
 
Upvote 0
As long as you will never insert any rows before or within the data (otherwise a different, longer formula would be needed), this array-entered** formula would work...

=20&MID(A1,MAX(IF(ISNUMBER(0+MID(A1,ROW($1:$99),1)),ROW($1:$99)))-1,2)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.

Hi Rick. How about if I have this entry:

Reconciliations for the month of December 2019 (IDR 3,850,000)
 
Upvote 0
Hi Rick. How about if I have this entry:

Reconciliations for the month of December 2019 (IDR 3,850,000)
Then my formula would not work. I would note, however, that none of your examples indicated here would or could be numbers after the year number you were looking for and, given we know absolutely nothing about your data, it would be impossible for us to guess that possibility from the examples you posted.


EDIT: I think it works now. I just need to change the Row($1:$99) to the number of rows I use.
The 99 in ROW($1:$99) was a guess at a number longer than the maximum length text in any one cell. If your maximum length text is, say, 324 characters, I would use 400 in place of the 99.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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