I confess I'm no expert of RegExp but the below is based on your narrative - the tests don't seem that convoluted that RegExp is an absolute necessity - however - for you to decide of course.
Function ParserTest(rngVal As Range, bType As Byte, Optional strDelim As String = " ")
Dim vVals As Variant, vSubVals As Variant, dblSize As String, lngQty As Long, lngVal As Long
vVals = Split(Application.WorksheetFunction.Trim(rngVal), strDelim)
If Val(vVals(UBound(vVals))) Then
dblSize = 1
lngQty = Val(vVals(UBound(vVals)))
Else
If InStr(vVals(UBound(vVals) - 1), "X") Then
vSubVals = Split(vVals(UBound(vVals) - 1), "X")
lngQty = vSubVals(0)
dblSize = vSubVals(1)
Else
Select Case UCase(Right(vVals(UBound(vVals)), 2))
Case "GM", "ML", "VL"
lngQty = 1
dblSize = 1 '? (default if unspecified - eg B13)
For lngVal = UBound(vVals) To LBound(vVals) Step -1
If IsNumeric(vVals(lngVal)) Then
dblSize = vVals(lngVal)
Exit For
End If
Next lngVal
Case Else 'unknown ?
dblSize = 1
lngQty = 1
End Select
End If
End If
ParserTest = IIf(bType = 1, dblSize, lngQty)
End Function
Called as before - eg: =PARSERTEST(B2,1) for Size - 2 for Qty.
Note: I'm not sure I followed all of your expected results but I suspect these nuances may be explained in your RegExp - I confess I've not looked in detail (based above on narrative).
Bookmarks