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.
DescriptionsPart numbers
Handle #09-ir2135ti#09-ir2135ti
D90-330-EX batteryD90-330-EX
VH202-02 steering wheelVH202-02
4964237 wiring teddy4964237
BPLR8CN 5" screwBPLR8CN

<tbody>
</tbody>

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.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
1Descriptionsfirst numberfirst spacesecond spacethird spacehelper columns Part numbers Part numbers
2Handle #09-ir2135ti97#VALUE!#VALUE!#09-ir2135ti#09-ir2135ti
3D90-330-EX battery211#VALUE!#VALUE!D90-330-EXD90-330-EX
4VH202-02 steering wheel3918#VALUE!VH202-02VH202-02
54964237 wiring teddy1815#VALUE!49642374964237
6BPLR8CN 5" screw5811#VALUE!BPLR8CNBPLR8CN
7johnson rod H202-0514812#VALUE!H202-05H202-05
8johnson rod long H202-06b1981217H202-06bH202-06b
9XH202-02 steering wheel wood391824XH202-02XH202-02

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet9

Worksheet Formulas
CellFormula
C2=SEARCH(" ",A2)
D2=SEARCH(" ",A2,C2+1)
E2=SEARCH(" ",A2,D2+1)
F2=IF(B2<C2,MID(A2,1,C2-1),MID(A2,AGGREGATE(14,6,C2:E2,1)+1,999))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
B2{=MATCH(TRUE,ISNUMBER(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1),0)}
G2{=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))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
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

Forum statistics

Threads
1,215,228
Messages
6,123,747
Members
449,118
Latest member
kingjet

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