Extract only 3 consecutive numbers from string

arembr01

New Member
Joined
Feb 16, 2014
Messages
10
I need to search a text string, find 3 consecutive numbers in a row, then extract the first two characters. I have given an example below. The 3 consecutive numbers will always be between "-" but the occurrence of "-" will vary. The numbers also might be stored as text within the string. The text string will only be in B2. It is a part number and will be updated by the user every time. Any help is greatly appreciated.




[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]5.3.1-WS11-564-4DB-MT[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]56[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]53.1-WS11-723-1DB-ABS[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]72[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]5.3.1-WS11-966-4DB-MT[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]96[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]63.1-WS11-564-3DB-MT[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]56[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]4.5.1-WS11-601-MT[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]33.1.WS11-564-6DB-UHMW[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]56[/TD]
[/TR]
[TR]
[TD][TABLE="width: 160"]
<tbody>[TR]
[TD="class: xl65, width: 160"]73.1-368-1DB-MT[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]36[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
This array-entered formula seems to do what you are asking for...

=INT(MAX(IFERROR(--MID(SUBSTITUTE(SUBSTITUTE(A1,".","X"),"-","X"),ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),3),0))/10)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0
This array-entered formula seems to do what you are asking for...

=INT(MAX(IFERROR(--MID(SUBSTITUTE(SUBSTITUTE(A1,".","X"),"-","X"),ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),3),0))/10)

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



Thank you very much for the help. However when I ran a few more tests I found a small issue. If the part number has a "/" in it then it doesn't give me the correct value.

6-TC-360-12/5DB results in 4313. It should be 36

7/3.1-WS11-484-4DB-MT results in 4328. It should be 48




[TABLE="width: 177"]
<tbody>[TR]
[TD="width: 177"] [/TD]
[/TR]
[TR]
[TD="width: 177"][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Thank you very much for the help. However when I ran a few more tests I found a small issue. If the part number has a "/" in it then it doesn't give me the correct value.

6-TC-360-12/5DB results in 4313. It should be 36

7/3.1-WS11-484-4DB-MT results in 4328. It should be 48
[TABLE="width: 177"]
<tbody>[TR]
[TD="width: 177"] [/TD]
[/TR]
[TR]
[TD="width: 177"][/TD]
[/TR]
</tbody>[/TABLE]
None of the seven examples you posted showed a slash in them so I did not know I had to work around them. Here is the fix (still an array-entered** formula)...

=INT(MAX(IFERROR(--MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"/","X"),".","X"),"-","X"),ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),3),0))/10)

**Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself
 
Upvote 0
None of the seven examples you posted showed a slash in them so I did not know I had to work around them. Here is the fix (still an array-entered** formula)...

=INT(MAX(IFERROR(--MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"/","X"),".","X"),"-","X"),ROW(INDEX(A:A,1):INDEX(A:A,LEN(A1))),3),0))/10)

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


I apologize, I didn't think about that example. But once again, thank you very much for your help.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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