excel formula to find maximum within same cell having multiple values of right most numbers

vrsharma

New Member
Joined
Aug 4, 2019
Messages
18
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I want to find maximum and minimum for right most number from same cell having multiple values, below is the how data looks. This all values are in same cell, ex: in cell "A1" I want to extract rightmost number, like 1.00,1.5,1.5,1.0,2.00,1.50,1.0,1.00 and find max and min from it. I am currently using Excel 2016 version.

BAEK1928_TXL_1.00
44444922_FLR2X-A_1.5
44447922_FL2X-B_1.5
44444922_FL2X-B_1.0
BAEK1928_TXL_2.00
44444922_FLR2X-B_1.50
44444922_FLR2X-A_1.0
44444922_FLRY-B_1.00

enter image description here
Is there any excel formula or vba code for it?
I have tried some excel formula as below but it doesn't work as required.
=MAX(RIGHT(A1,LEN(A1)-FIND("_",A1,SEARCH("_",A1)+1))
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about, for
VBA Code:
Function GetMax(Txt As String) As Double
    Dim Sp As Variant
    Dim i As Long
    Dim x As Double
    
    Sp = Split(Txt, Chr(10))
    For i = 0 To UBound(Sp)
        x = Right(Sp(i), Len(Sp(i)) - InStrRev(Sp(i), "_"))
        If GetMax < x Then GetMax = x
    Next i
End Function
and
VBA Code:
Function GetMin(Txt As String) As Double
    Dim Sp As Variant
    Dim i As Long
    Dim x As Double
    
    GetMin = 10 ^ 9
    Sp = Split(Txt, Chr(10))
    For i = 0 To UBound(Sp)
        x = Right(Sp(i), Len(Sp(i)) - InStrRev(Sp(i), "_"))
        If GetMin > x Then GetMin = x
    Next i
End Function

Used like
Book1
ABC
1BAEK1928_TXL_.001 44444922_FLR2X-A_1.5 44447922_FL2X-B_1.5 44444922_FL2X-B_1.0 BAEK1928_TXL_2.00 44444922_FLR2X-B_1.50 44444922_FLR2X-A_1.0 44444922_FLRY-B_1.0020.001
Sheet2
Cell Formulas
RangeFormula
B1B1=GetMax(A1)
C1C1=getmin(A1)
 
Upvote 0
with Power Query
Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Split = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByDelimiter("#(lf)", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    Extract = Table.TransformColumns(Split, {{"Column1", each Text.AfterDelimiter(_, "_", {0, RelativePosition.FromEnd}), type text}}),
    One = Table.AddColumn(Table.TransformColumnTypes(Extract,{{"Column1", type number}}), "Custom", each 1),
    Group = Table.Group(One, {"Custom"}, {{"min", each List.Min([Column1]), type number}, {"max", each List.Max([Column1]), type number}}),
    ROC = Table.SelectColumns(Group,{"min", "max"})
in
    ROC
minmax.jpg
 
Upvote 0
How about, for
VBA Code:
Function GetMax(Txt As String) As Double
    Dim Sp As Variant
    Dim i As Long
    Dim x As Double
   
    Sp = Split(Txt, Chr(10))
    For i = 0 To UBound(Sp)
        x = Right(Sp(i), Len(Sp(i)) - InStrRev(Sp(i), "_"))
        If GetMax < x Then GetMax = x
    Next i
End Function
and
VBA Code:
Function GetMin(Txt As String) As Double
    Dim Sp As Variant
    Dim i As Long
    Dim x As Double
   
    GetMin = 10 ^ 9
    Sp = Split(Txt, Chr(10))
    For i = 0 To UBound(Sp)
        x = Right(Sp(i), Len(Sp(i)) - InStrRev(Sp(i), "_"))
        If GetMin > x Then GetMin = x
    Next i
End Function

Used like
Book1
ABC
1BAEK1928_TXL_.001 44444922_FLR2X-A_1.5 44447922_FL2X-B_1.5 44444922_FL2X-B_1.0 BAEK1928_TXL_2.00 44444922_FLR2X-B_1.50 44444922_FLR2X-A_1.0 44444922_FLRY-B_1.0020.001
Sheet2
Cell Formulas
RangeFormula
B1B1=GetMax(A1)
C1C1=getmin(A1)

Thank you Fluff, it worked very well
 
Upvote 0
with Power Query
Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Split = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column1", Splitter.SplitTextByDelimiter("#(lf)", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column1"),
    Extract = Table.TransformColumns(Split, {{"Column1", each Text.AfterDelimiter(_, "_", {0, RelativePosition.FromEnd}), type text}}),
    One = Table.AddColumn(Table.TransformColumnTypes(Extract,{{"Column1", type number}}), "Custom", each 1),
    Group = Table.Group(One, {"Custom"}, {{"min", each List.Min([Column1]), type number}, {"max", each List.Max([Column1]), type number}}),
    ROC = Table.SelectColumns(Group,{"min", "max"})
in
    ROC
View attachment 1624

Thanks sandy, for this interesting solution.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Hi, here is a formula you could also try, note that this is currently hard coded for a maximum of 10 values in any one cell, this maximum can be increased or made dynamic if needed.

The formula makes use of a technique for parsing delimited strings which can be found here:


Book1
ABC
1BAEK1928_TXL_.001 44444922_FLR2X-A_1.5 44447922_FL2X-B_1.5 44444922_FL2X-B_1.0 BAEK1928_TXL_2.00 44444922_FLR2X-B_1.50 44444922_FLR2X-A_1.0 44444922_FLRY-B_1.000.0012
Sheet1
Cell Formulas
RangeFormula
B1B1=AGGREGATE(15,6,0+TRIM(RIGHT(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A1,CHAR(10),REPT(" ",LEN(A1))),{1,2,3,4,5,6,7,8,9,10}*LEN(A1)-(LEN(A1)-1),LEN(A1))),"_",REPT(" ",15)),15)),1)
C1C1=AGGREGATE(14,6,0+TRIM(RIGHT(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A1,CHAR(10),REPT(" ",LEN(A1))),{1,2,3,4,5,6,7,8,9,10}*LEN(A1)-(LEN(A1)-1),LEN(A1))),"_",REPT(" ",15)),15)),1)
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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