Here is a complicated formula that
- Splits the string into an array of individual words, separated by
space
or underscore
- looks for a word that matches the pattern
nnnxnnn
defined as:
- Starts with a number
- followed by a lower case
x
(if the x
could be either case, replace FIND
with SEARCH
in the formulas below)
- ends with a number
- The function will return the last word in the string that matches that pattern.
The formula includes several "sub formulas"
We split the string by both space
and underscore
into an array of words:
=TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99))
In the above SEQ
is a Named Formula: ( Formulas ► Define Name
)
=IF((ROW(INDEX(Sheet1!$1:$65536,1,1):INDEX(Sheet1!$1:$65536,255,1))-1)*99=0,1,(ROW(INDEX(Sheet1!$1:$65536,1,1):INDEX(Sheet1!$1:$65536,255,1))-1)*99)
That formula generates a series of numbers 1,99,198,297, ...
which provides a good starting point for the MID
function in the first formula.
We then use LEFT and MID functions to find the words that contain an x
, and have numbers before and after the x
ISNUMBER(-LEFT(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)),FIND("x",TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)))-1))
ISNUMBER(-MID(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)),FIND("x",TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)))+1,99)))
Multiplying those two formulas will return an array of 0's and 1's for words that match or do not match the pattern.
1/(...)
will then return an array of 1
or DIV/0
errors.
Using the vector form of LOOKUP
will then return the value in our string array that is in the same position as the match in our pattern matching array.
=LOOKUP(2,1/(ISNUMBER(-LEFT(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)),FIND("x",TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)))-1))*ISNUMBER(-MID(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)),FIND("x",TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)))+1,99))),TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"_"," ")," ",REPT(" ",99)),SEQ,99)))

I would note that using VBA and Regular Expressions, that same pattern can be expressed a \d+x\d+
and a User Defined Function can be used accomplishing the same thing, taking a fraction of the time to devise once you are fluent;
Option Explicit
Function ExtractMeasure(S As String) As String
Dim RE As Object, MC As Object
Set RE = CreateObject("vbscript.regexp")
With RE
.Pattern = "\d+x\d+"
.Global = False
.ignorecase = False 'Case Sensitive
If .test(S) = True Then
Set MC = .Execute(S)
ExtractMeasure = MC(0)
End If
End With
End Function