16

I'm looking for a function in Excel that looks something like

= MAX(ABS(A1:A10))

except ABS() doesn't take a range of numbers.

The best that I can come up with is:

= MAX(ABS(MIN(A1:A10)),ABS(MAX(A1:A10)))

It does the trick, but it's messy as all heck and I can't believe there's not a better way. Any ideas?

10 Answers 10

26

You must enter it as an array formula. Do so by pressing Ctrl.+Shift+Enter. The formula will appear as {=MAX(ABS(A1:A10))} if done correctly.

4
  • 7
    Note to numb-skulls like myself: Enter the formula then press Ctrl+Shift+Enter, I was trying to press ctrl+shift+enter first, then enter the formula, that didn't really work so well. :P
    – user160917
    Oct 14, 2011 at 19:26
  • 1
    Excel is not user-friendly when it comes to matrix formulas. It behaviors is really annoying.
    – Pedro77
    May 7, 2014 at 17:30
  • It is not mandatory to use an array formula (see this and this. Moreover, it might be inconvenient. Nov 20, 2014 at 2:23
  • 3
    This returns an error if your range also contains non-numeric data (e.g. text or formula errors)
    – CBRF23
    Feb 6, 2015 at 15:41
27

I don't like arrays so I would use the following:

=MAX(-MIN(range), MAX(range))

This works because the only time the absolute of the minimum number would be higher that the maximum value is if it is a negative number.

4
  • This works if your range also contains non-numeric data (e.g. text or formula errors)
    – CBRF23
    Feb 6, 2015 at 15:40
  • Nice, this is a missing feature in excel, why not max(abs()) ??
    – Pedro77
    May 31, 2017 at 23:21
  • @Julie your now +5yr old answer still has an audience. :) You propose an alternative which avoids using the array function, which you indicate you consider a plus. Do you still dislike array functions? Could you comment on why you do not (or did not) like array functions? Knowing more about your considerations might help me and other readers evaluate which solution we would like to use in which context.
    – pjvleeuwen
    Jan 21, 2019 at 23:17
  • This also works in OpenOffice Jun 18, 2019 at 10:30
3

Try this formula (from here)

=MAX(INDEX(ABS(A1:A10),0,1))

It combines:

  • The benefits of a non-array formula, as in this answer above (see this for the benefits of non-array).
  • Entering the target range only once, as in this answer above (less prone to errors, and easier to modify).
1

This VBA solution works too.

Public Function absMax(values As Range)
    'returns the largest absolute value in a list of pos and neg numbers

    Dim myArray() As Double, i As Integer, numel As Integer
    numel = values.count
    ReDim myArray(1 To numel)
    For i = 1 To numel
        myArray(i) = Abs(values(i))
    Next i
    absMax = WorksheetFunction.Max(myArray)

End Function
  1. Open your VBA editor (Alt+F11)
  2. Insert a new module on the right pane
  3. Copy & paste the code to the module
  4. Go back to Excel and use =absMax(A1:A3)

enter image description here

1

=IF(-MIN(range)>MAX(range),MIN(range),MAX(range))

This will return the largest magnitude number while preserving the sign.

0
=IF(ABS(LARGE(A1:A10,1))>ABS(SMALL(A1:A10,1)),LARGE(A1:A10,1),SMALL(A1:A10,1))

This will find the value with the largest absolute value out of the range but still return the actual value with its original sign (+/-) and not the absolute value.

3
  • (1) As you know, this is not an answer to this question.  It is the answer to a different question.  We prefer to keep answers with the questions that they go with.  If you really want to post this answer, you might want to “ask” the corresponding question and then answer it.  (You are allowed to do that, but, since you have a low reputation, you might have to wait several hours before you can answer your own question.) Apr 22, 2015 at 20:56
  • (2) The OP already has a working answer to the question, and rejects it because “it’s messy as all heck and I can’t believe there’s not a better way.”  So why post an answer that’s twice as long as the one he already has?  For that matter, why not say just =IF(ABS(MAX(A1:A10))>ABS(MIN(A1:A10)),MAX(A1:A10),MIN(A1:A10))? Apr 22, 2015 at 20:57
  • @G-Man This is the only formula solution, posted so far, that keeps the original sign intact, which is not explicitly requested by the OP but was helpful to me. I respectfully disagree with both your assessments. Oct 6, 2015 at 16:23
0

=MAX(MAX(X1:X5),ABS(MIN(X1:X5)))

2
  • so how is it different from Julie's answer?
    – phuclv
    Nov 14, 2017 at 8:46
  • This is an answer to the question (belated, yes). Similar to Julie's, yes, slightly less efficient, perhaps, but IMHO a bit more obvious for someone who inherits the spreadsheet.
    – xenoid
    Nov 14, 2017 at 16:19
0

As of Office 365, the version posted by the OP works.

= MAX(ABS(A1:A10))

You do NOT have to use array mode.

enter image description here

0

I needed to find the max and min deviation from zero, irrespective of the sign. However, I found no way to do that using standard Excel functions when both positive and negative numbers are involved. So, I created my own VBA functions (based on code I found elsewhere) that works every time, even when some of the values are null or strings (non-numeric).

Here are the two functions MAX_ABS(range) and MIN_ABS(range, [optional boolean] allowZeros)

MAX_ABS is simple and straightforward:

Function MAX_ABS(SelectRng As Range) As Double
    Dim result As Double
    Dim work As Double
    result = 0
    
    myarray = SelectRng.Value
    
    For i = 1 To UBound(myarray, 1)
        For j = 1 To UBound(myarray, 2)
            If IsNumeric(myarray(i, j)) = True Then     'Numbers Only
                work = VBA.Abs(myarray(i, j))
                If work > VBA.Abs(result) Then          'Test
                    result = myarray(i, j)              'Save new max
                End If
            End If
        Next
    Next
    
    MAX_ABS = result
    
End Function

MIN_ABS is a bit trickier because if you initialize the return value to zero then it will always return zero, so you need to work around that. So I use an optional boolean parameter to allow zeros or ignore them.

Function MIN_ABS(SelectRng As Range, Optional allowZeros As Boolean = False) As Double
    Dim work As Double
    Dim result As Double
    Dim firstHit As Boolean
    result = 0
    firstHit = True
    
    myarray = SelectRng.Value
    
    For i = 1 To UBound(myarray, 1)
        For j = 1 To UBound(myarray, 2)
        
             If IsNumeric(myarray(i, j)) = True Then                'Numbers Only
                work = VBA.Abs(myarray(i, j))
                
                'Zeros allowed
                If allowZeros = True Then
                    If firstHit = True Then                         'First pass -- Initialize
                        firstHit = False
                        result = myarray(i, j)                      'Save first value
                        
                    ElseIf work < VBA.Abs(result) Then              'Subsequent pass -- Test
                        result = myarray(i, j)                      'Save new min
                    End If
                    If work = 0 Then
                        GoTo getout                                 'Zero -- no reason for further tests
                    End If
                    
                'Zeros not allowed
                ElseIf result = 0 And work > 0 Then                 'First pass -- Initialize
                    result = myarray(i, j)
                ElseIf work > 0 And work < VBA.Abs(result) Then     'Subsequent pass -- Test
                    result = myarray(i, j)
                End If
            End If
        Next
    Next
    
getout:
    
    MIN_ABS = result

End Function

Here are the results of the functions on a list of values that includes numbers, strings, and blanks.

Results of MAX_ABS and MIN_ABS

-1
=IF(MAX(A1:A10)+MIN(A1:A10)>0, MAX(A1:A10), MIN(A1:A10))
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .