Extract multiple 5-digit numbers from alphanumeric text

jkg77

New Member
Joined
Jun 9, 2017
Messages
5
Hello,


I need to extract multiple 5-digit numbers from a cell that contains both letters and numbers. I found a thread that solves for how to extract a single number but this doesn't work for me because my data might contain multiple 5-digit numbers.


Here is an example of how my data looks (column A). I would like to extract the 5-digit numbers to column B.


I would like to have the 5-digit numbers in the same cell, separated by commas. Also, the data might contain numbers that are more or less than 5 digits - these should be ignored.


Thank you!

Column AColumn B
1One number is 12345. And a second number is 54321.12345, 54321
2There is just 1 five digit number: 7363873638
3There is 1 five digit number (00293) but also 1 six digit number (038822), which should be ignored. Numbers might have leading zeros.00293
412345, 54321, and 55555.....but not ABC123 or 123ABC.12345, 54321, 55555

<tbody>
</tbody>
 
It seems my formula in post #8 does not extract the 5-digit number if it is the first substring of the string. Corrected version in cell C1:

=IFERROR(TEXT(LARGE(IF(NOT(ISNUMBER(--(MID(" "&$A1,ROW($1:$200),1))))*ISNUMBER(--(MID(" "&$A1,ROW($1:$200)+1,5)&"."))*NOT(ISNUMBER(--(MID(" "&$A1,ROW($1:$200)+6,1))))=1,--MID(" "&$A1,ROW($1:$200)+1,5),""),COLUMN()-2),"00000"),"")

Hi István,

Maybe I'm wrong, but I think that your formula still have problem.

Try this small modification in your formula:

=IFERROR(TEXT(LARGE(IF(NOT(ISNUMBER(-(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1))))*ISNUMBER(-(MID($A2&" ",ROW(INDIRECT("1:"&LEN($A2)))+1,5)&","))*
NOT(ISNUMBER(-(MID($A2,ROW(INDIRECT("1:"&LEN($A2)))+6,1)))),1*MID($A2,ROW(INDIRECT("1:"&LEN($A2)))+1,5),""),COLUMNS($C1:C1)),"00000"),"")

Markmzz
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi István,

Maybe I'm wrong, but I think that your formula still have problem.

Try this small modification in your formula:

=IFERROR(TEXT(LARGE(IF(NOT(ISNUMBER(-(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1))))*ISNUMBER(-(MID($A2&" ",ROW(INDIRECT("1:"&LEN($A2)))+1,5)&","))*
NOT(ISNUMBER(-(MID($A2,ROW(INDIRECT("1:"&LEN($A2)))+6,1)))),1*MID($A2,ROW(INDIRECT("1:"&LEN($A2)))+1,5),""),COLUMNS($C1:C1)),"00000"),"")

Markmzz

Thanks, this is my corrected version:

=IFERROR(TEXT(LARGE(IF(NOT(ISNUMBER(--(MID(" "&$A2&" ",ROW($1:$200),1))))*ISNUMBER(--(MID(" "&$A2&" ",ROW($1:$200)+1,5)&"."))*NOT(ISNUMBER(--(MID(" "&$A2&" ",ROW($1:$200)+6,1))))=1,--MID(" "&$A2&" ",ROW($1:$200)+1,5),""),COLUMN()-2),"00000"),"")
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,689
Members
449,117
Latest member
Aaagu

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