Hi and welcome to the forum.
Below is a VBA solution to your problem.
The initial problem is that your data has various deliminators, i.e., "x", "-", "~", " ", etc.
I have created a function to standardize the delimator as a hash mark, "#".
First we set up an array containing the delimators we want to convert. You can add to the list by editing this line of the function:
Code:
[COLOR=green]'add more if necessary[/COLOR],[COLOR=SeaGreen] remember to seperate with a comma[/COLOR]
arrSpecialChars = Array("x", "~", "-")
We then loop through this array replacing these characters with the hash mark and remove any spaces.
Code:
[COLOR=green]'replace the special characters with a hash mark[/COLOR]
[COLOR=darkblue]For[/COLOR] i = [COLOR=darkblue]LBound[/COLOR](arrSpecialChars) [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](arrSpecialChars)
txt = Replace(txt, arrSpecialChars(i), "#", vbTextCompare)
[COLOR=darkblue]Next[/COLOR] i
[COLOR=green]'remove spaces[/COLOR]
txt = Replace(txt, " ", "", vbTextCompare)
i.e., within the code code your data will look like:
10mm
14.2#198.3#23mm
#3#5.5mm
10#15.5#20mm
This is something we can use.
The ExtractMax procedure.
I have assumed your data is on Sheet1 starting in cell A1.
We loop through column A until we find an empty cell.
We call the function to standardize deliminators, where
rng is a cell in column A:
Code:
txt = ReplaceSpecialCharacters(rng.Value)
We then use the
Split() function to seperate the
txt string into an array, using the hash mark as a deliminator:
Code:
[COLOR=green]'split the txt string into an array[/COLOR]
arrMax = Split(txt, "#")
====================
Edit: For example, the array will store this value
14.2x198.3x23mm as:
arrMax(0) =14.2
arrMax(1)=198.3
arrMax(2)=3.23
We set he max value as the first and loop through the array to see if we can find a larger value.
========================
And we loop through the array to find the maximum value.
Code:
[COLOR=green]'find the max value[/COLOR]
max = Val(arrMax(0))
[COLOR=darkblue]For[/COLOR] i = [COLOR=darkblue]LBound[/COLOR](arrMax) [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](arrMax)
[COLOR=darkblue]If[/COLOR] Val(arrMax(i)) > max [COLOR=darkblue]Then[/COLOR]
max = Val(arrMax(i))
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Next[/COLOR] i
Which is output to column B
Code:
[COLOR=green]'output[/COLOR]
rng.Offset(, 1).Value = max
The full code is shown below.
To use, cretae a copy of your workbook.
Open the copy and press
Alt+F11 to open the vBA editor.
Double click the
ThisWorkbook module in the
Project Window on the left hand side.
Copy and paste the code below.
Edit where highlighted if necessary.
Press
F5 to run.
Code:
[COLOR=darkblue]Sub[/COLOR] ExtractMax()
[COLOR=darkblue]Dim[/COLOR] rng [COLOR=darkblue]As[/COLOR] Range
[COLOR=darkblue]Dim[/COLOR] txt [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
[COLOR=darkblue]Dim[/COLOR] max [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] arrMax [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR] [COLOR=green]'loop variant[/COLOR]
[COLOR=darkblue]Set[/COLOR] rng = Sheets("[COLOR=Red]Sheet1[/COLOR]").Range("[COLOR=Red]A1[/COLOR]")
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] rng = ""
txt = ReplaceSpecialCharacters(rng.Value)
[COLOR=green]'split the txt string into an array[/COLOR]
arrMax = Split(txt, "#")
[COLOR=green]'find the max value[/COLOR]
max = Val(arrMax(0))
[COLOR=darkblue]For[/COLOR] i = [COLOR=darkblue]LBound[/COLOR](arrMax) [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](arrMax)
[COLOR=darkblue]If[/COLOR] Val(arrMax(i)) > max [COLOR=darkblue]Then[/COLOR]
max = Val(arrMax(i))
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Next[/COLOR] i
[COLOR=green]'output[/COLOR]
rng.Offset(, 1).Value = max
[COLOR=darkblue]Set[/COLOR] rng = rng.Offset(1, 0)
[COLOR=darkblue]Loop[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Function[/COLOR] ReplaceSpecialCharacters([COLOR=darkblue]ByRef[/COLOR] txt [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]) [COLOR=darkblue]As[/COLOR] String
[COLOR=darkblue]Dim[/COLOR] arrSpecialChars [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
[COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR] [COLOR=green]'loop index[/COLOR]
[COLOR=green]'add more if necessary[/COLOR]
arrSpecialChars = Array("x", "~", "-")
[COLOR=green]'replace the special characters with a hash mark[/COLOR]
[COLOR=darkblue]For[/COLOR] i = [COLOR=darkblue]LBound[/COLOR](arrSpecialChars) [COLOR=darkblue]To[/COLOR] [COLOR=darkblue]UBound[/COLOR](arrSpecialChars)
txt = Replace(txt, arrSpecialChars(i), "#", vbTextCompare)
[COLOR=darkblue]Next[/COLOR] i
[COLOR=green]'remove spaces[/COLOR]
txt = Replace(txt, " ", "", vbTextCompare)
[COLOR=green]'output result[/COLOR]
ReplaceSpecialCharacters = txt
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Function[/COLOR]