Maximum / Highest Value of a cell

RAMU

Active Member
Joined
Dec 11, 2009
Messages
345
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
Dear Friends,

I have a workbook where cells are carrying values like the following:

2~~5~~18~~-15
-11~~-60~~-3
55~~80

More surprisingly sometimes there is a space after~~ sometimes there isn't like this
20~~50~~60
30~~ 60~~ 70

I badly need a formula which will give me the highest value of those cells
That means:
2~~5~~18~~-15 = Desired Result is 18

But the formula will work irrespective the space.
Thanks in advance
Regards
RAMU
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Dear Friends,

I have a workbook where cells are carrying values like the following:

2~~5~~18~~-15
-11~~-60~~-3
55~~80

More surprisingly sometimes there is a space after~~ sometimes there isn't like this
20~~50~~60
30~~ 60~~ 70

I badly need a formula which will give me the highest value of those cells
That means:
2~~5~~18~~-15 = Desired Result is 18

But the formula will work irrespective the space.
Thanks in advance
Regards
RAMU


Excel 2010
ABCD
2~~5~~18~~
-11~~-60~~-3
55~~80
2~~5~~18~~
20~~50~~60
30~~ 60~~ 70
2~~5~~18~~-15

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"]18[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"]-3[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]80[/TD]
[TD="align: right"][/TD]
[TD="align: right"]80[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"]18[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]60[/TD]
[TD="align: right"][/TD]
[TD="align: right"]60[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]70[/TD]
[TD="align: right"][/TD]
[TD="align: right"]70[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"]18[/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet4

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]B1[/TH]
[TD="align: left"]=MATCH(1000,INDEX(FIND(","&ROW(INDIRECT("1:999"))&",",","&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ",""),"~",",0,"),",,",",0,")&","),0))[/TD]
[/TR]
[TR]
[TH][/TH]
[TD="align: left"][/TD]
[/TR]
[TR]
[TH]D1[/TH]
[TD="align: left"]=HighVal(A1)[/TD]
[/TR]
[TR]
[TH][/TH]
[TD="align: left"][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

The Excel Formula works great unless you only have negative numbers.

The UDF works regardless of positive or negative numbers


If you're interested in the UDF: Create a new Module within the VBA editor and paste the following:

Code:
Public Function HighVal(StrIn As String) As Integer


    Dim TmpStr As String
    Dim StrArray() As String, IntArray() As Integer
    Dim Cntr As Integer, IntCntr As Integer
    
    
    
    TmpStr = WorksheetFunction.Substitute(StrIn, " ", "")
    TmpStr = WorksheetFunction.Substitute(TmpStr, "~", ",`,")
    TmpStr = WorksheetFunction.Substitute(TmpStr, ",,", ",`,")
    
    If Right(TmpStr, 1) = "," Then TmpStr = Left(TmpStr, Len(TmpStr) - 1)


    StrArray = Split(TmpStr, ",")
    
    For Cntr = 1 To UBound(StrArray)
        If StrArray(Cntr) <> "`" Then
            IntCntr = IntCntr + 1
            ReDim Preserve IntArray(1 To IntCntr)
            IntArray(IntCntr) = CInt(StrArray(Cntr))
        End If
    Next Cntr


    HighVal = WorksheetFunction.Max(IntArray)


End Function


Hope this helps!
 
Last edited:
Upvote 0
Dear Friend,

Thnx for your help, but my file is so heavy that I don't want to use VBA. Is it not at all possible using formula only ?
But unfortunately few cells are carrying negative value only like -9~~-22~~-3 & -2~~-60~~-85.
If possible please help, otherwise I have to go with VBA ultimately.
 
Upvote 0
In A2 control+shift+enter, not just enter, and copy down:

=MAX(eval("{"&SUBSTITUTE(TRIM(SUBSTITUTE(A3,"~"," "))," ",",")&"}"))

For this formula to work, you need to install the following udf as a module, using Alt+F11...

_________________________

Public Function EVAL(theInput As Variant) As Variant
'
' if UDF evaluate the input string as though it was on this sheet
' else evaluate for activesheet
'
Dim vEval As Variant
Application.Volatile
On Error GoTo funcfail
If Not IsEmpty(theInput) Then
If TypeOf Application.Caller.Parent Is Worksheet Then
vEval = Application.Caller.Parent.Evaluate(CStr(theInput))
Else
vEval = Application.Evaluate(CStr(theInput))
End If
If IsError(vEval) Then
EVAL = CVErr(xlErrValue)
Else
EVAL = vEval
End If
End If
Exit Function
funcfail:
EVAL = CVErr(xlErrNA)
End Function
_________________________
 
Upvote 0
Thanks for helping me. It works gr8...!!!
 
Upvote 0
The following array formula can handle if the length of the data in the cells are bit longer ....

(should be entered by Ctrl+Shift+Enter)


Code:
=MAX(IF(ISERR(TRIM(MID(SUBSTITUTE(SUBSTITUTE(TRIM(A1),"~"," ")," ",REPT(" ",100)),100*ROW($1:$900),100))+0),"-2,2251 E-308",TRIM(MID(SUBSTITUTE(SUBSTITUTE(TRIM(A1),"~"," ")," ",REPT(" ",100)),100*ROW($1:$900),100))+0))

 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

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