Extract Numbers from a String of Text

bobzy20

New Member
Joined
Feb 5, 2018
Messages
41
Office Version
  1. 2010
Hi

I hope somebody can help me with this.

I’m looking for a way to extract a 7 digit number from a string of text, see my examples below. The number could be anywhere in the string.

Sanyo Yamaha II Slow Control Rod NEW 5841258 25984
Sanyo 4579542 Yamaha II Slow Controller NEW 12584
Sanyo Yamaha II Plastic Bag NEW 1248652 25489
Sanyo Yamaha II 9405566 Tool Bag NEW / 5894526
Sanyo Yamaha II/Super Car 1257945 Screw Bag C NEW 25689
Sanyo Yamaha Metal Parts 1584520 Bag NEW 56974

Thanks

Bob
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Enter into B1 and try:

=MID(A1,FIND(" "&REPT("|",7)&" ",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(" "&A1&" ","0","|"),"1","|"),"2","|"),"3","|"),"4","|"),"5","|"),"6","|"),"7","|"),"8","|"),"9","|"),","," "),":"," "),";"," "),REPT("|",7)&". ",REPT("|",7)&" ")),7)
 
Upvote 0
Welcome to the MrExcel board!

IF your sample data is representative of your real data, then perhaps this might also suffice.

=AGGREGATE(14,6,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-6)),7)+0,1)
 
Last edited:
Upvote 0
Welcome to the MrExcel board!

IF your sample data is representative of your real data, then perhaps this might also suffice.

=AGGREGATE(14,6,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-6)),7)+0,1)

At me, 12345 is extracted from "er 12345 t". Is it my regional (number) settings?
 
Upvote 0
Thanks very much, my real text if different to the sample text so didn't work correctly. The real strings of text have lots of different part numbers, some with 000 at the beginning which your code seems to ignore.
 
Upvote 0
At me, 12345 is extracted from "er 12345 t". Is it my regional (number) settings?
That is (partly) why I qualified my post with "IF the sample data was representative of the real data". All the sample data examples contained a 7-digit number surrounded by spaces & also no numbers greater than 7 digits. Your example is different to the OP's samples on the first point. :)


The real strings of text have lots of different part numbers, some with 000 at the beginning which your code seems to ignore.
In that case, does this work? If not, could you give a more representative set of sample data and the expected results?

=MID(AGGREGATE(14,6,(9&MID(A1,ROW(INDIRECT("1:"&LEN(A1)-6)),7))+0,1),2,7)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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