Extract variable alphanumeric thread from alphanumeric thread

LDNeedsHelp

New Member
Joined
Feb 29, 2016
Messages
4
Hi there,

I have a list of part descriptions that I need to extract part numbers from. These part numbers may be purely numeric, alphanumeric, or contain hyphens, underscores or special characters:
e.g.
[TABLE="width: 500"]
<tbody>[TR]
[TD]Descriptions[/TD]
[TD]Part numbers [/TD]
[/TR]
[TR]
[TD]Handle #09-ir2135ti[/TD]
[TD]#09-ir2135ti[/TD]
[/TR]
[TR]
[TD]D90-330-EX battery[/TD]
[TD]D90-330-EX[/TD]
[/TR]
[TR]
[TD]VH202-02 steering wheel[/TD]
[TD]VH202-02[/TD]
[/TR]
[TR]
[TD]4964237 wiring teddy[/TD]
[TD]4964237[/TD]
[/TR]
[TR]
[TD]BPLR8CN 5" screw[/TD]
[TD]BPLR8CN[/TD]
[/TR]
</tbody>[/TABLE]

I need something to extract:
1. string of numbers (if only numbers need >4 numbers to make a string)
2. string of numbers and letters or special characters

I'm hoping the logic can look for strings between spaces that include both letters and numbers to distinguish them from the text...

Would really appreciate any guidance anyone can offer!

Many thanks in advance.
 
I think this might help. I added some extra sample records for testing purposes. One formula relies on helper columns (Columns B through E) and the other is a standalone. Both formulas report text only.

It will only work for Descriptions that have one, two or three spaces and only for Descriptions that contain at least one number; it does not matter whether the unwanted text comes first or last.

Note: this text editor is messing up when displaying the formulas.<c2,mid(a2,1,c2-1),mid(a2,aggregate(14,6,c2:e2,1)+1,999))
I'll make two posts.<c2,mid(a2,1,c2-1),mid(a2,aggregate(14,6,c2:e2,1)+1,999))

</c2,mid(a2,1,c2-1),mid(a2,aggregate(14,6,c2:e2,1)+1,999))
</c2,mid(a2,1,c2-1),mid(a2,aggregate(14,6,c2:e2,1)+1,999))
 
Last edited:
Upvote 0
Let's see if this works right.

ABCDEFG
Descriptionsfirst numberfirst spacesecond spacethird space
Handle #09-ir2135ti
D90-330-EX battery
VH202-02 steering wheel
4964237 wiring teddy
BPLR8CN 5" screw
johnson rod H202-05
johnson rod long H202-06b
XH202-02 steering wheel wood

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="bgcolor: #FCE4D6"]helper columns Part numbers [/TD]
[TD="bgcolor: #FCE4D6"]Part numbers [/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]9[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA"]#09-ir2135ti[/TD]
[TD="bgcolor: #C6E0B4"]#09-ir2135ti[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA"]D90-330-EX[/TD]
[TD="bgcolor: #C6E0B4"]D90-330-EX[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA"]VH202-02[/TD]
[TD="bgcolor: #C6E0B4"]VH202-02[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA, align: right"]4964237[/TD]
[TD="bgcolor: #C6E0B4, align: right"]4964237[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]5[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA"]BPLR8CN[/TD]
[TD="bgcolor: #C6E0B4"]BPLR8CN[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]14[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]#VALUE![/TD]
[TD="bgcolor: #E2EFDA"]H202-05[/TD]
[TD="bgcolor: #C6E0B4"]H202-05[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]19[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]12[/TD]
[TD="align: right"]17[/TD]
[TD="bgcolor: #E2EFDA"]H202-06b[/TD]
[TD="bgcolor: #C6E0B4"]H202-06b[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"]24[/TD]
[TD="bgcolor: #E2EFDA"]XH202-02[/TD]
[TD="bgcolor: #C6E0B4"]XH202-02[/TD]

</tbody>
Sheet9

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: #DAE7F5"]C2[/TH]
[TD="align: left"]=SEARCH(" ",A2)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]D2[/TH]
[TD="align: left"]=SEARCH(" ",A2,C2+1)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]E2[/TH]
[TD="align: left"]=SEARCH(" ",A2,D2+1)[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]F2[/TH]
[TD="align: left"]=IF(B2<C2,MID(A2,1,C2-1),MID(A2,AGGREGATE(14,6,C2:E2,1)+1,999))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #DAE7F5"]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: #DAE7F5"]B2[/TH]
[TD="align: left"]{=MATCH(TRUE,ISNUMBER(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1),0)}[/TD]
[/TR]
[TR]
[TH="width: 10, bgcolor: #DAE7F5"]G2[/TH]
[TD="align: left"]{=IF(MATCH(TRUE,ISNUMBER(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1),0)<SEARCH(" ",A2),MID(A2,1,SEARCH(" ",A2)-1),MID(A2,MAX(IFERROR(SEARCH(" ",A2,SEARCH(" ",A2,SEARCH(" ",A2)+1)+1),0),IFERROR(SEARCH(" ",A2,SEARCH(" ",A2)+1),0),SEARCH(" ",A2))+1,999))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
The formula in F2 should display as b2 < A2 at the start.
 
Upvote 0
I think this UDF will do what you want.
Note that the optional incidence augment allows you to extract more than one part number from a string if it exists.
Code:
Function PartNumber(aString As String, Optional Incidence As Long = 1) As String
    Dim Words As Variant, oneWord As String
    Dim i As Long
    Words = Split(aString, " ")
    For i = 0 To UBound(Words)
        oneWord = LCase(Words(i))
        
        If Not (oneWord Like "*[!a-z]*") Then
            Rem word is all letters, reject
        ElseIf Not (oneWord Like "*[!0-9]*") Then
            Rem word is all numerals
            If Len(oneWord) < 4 Then
                Rem word is 1, 2 or 3 digit numeral, reject
            Else
                Rem long numberal, accept
                Incidence = Incidence - 1
            End If
        ElseIf oneWord Like "*[a-z]*" Then
            Rem contains at least one letter, accept
            Incidence = Incidence - 1
        End If
        If Incidence = 0 Then
            PartNumber = Words(i)
            Exit For
        End If
    Next i
End Function
 
Last edited:
Upvote 0

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