Closed Thread
Results 1 to 15 of 15

Returning greatest (absolute) value, including negatives

  1. #1
    Registered User
    Join Date
    02-09-2011
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Returning greatest (absolute) value, including negatives

    Hi,

    I have a range of numbers from -100 to 100 in a row, and would like to return the greatest absolute value, including the negative sign if it happens to be a negative value.

    i.e. if the number happens to be -70, using the =ABS function only returns "70", instead of -70.
    Using the =MAX function also only returns the greatest positive value, even if there is a larger negative absolute value.

    Thanks
    Last edited by romperstomper; 07-08-2011 at 05:35 PM. Reason: Mark solved

  2. #2
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Returning greatest (absolute) value, including negatives

    Use this:

    Please Login or Register  to view this content.
    Entered with Ctrl-Shift-Enter.

    Cheers,
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  3. #3
    Registered User
    Join Date
    02-09-2011
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Returning greatest (absolute) value, including negatives

    Sorry, I've done the above, but it still returns any negative values as its positive (i.e. without the negative sign).

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Returning greatest (absolute) value, including negatives

    Maybe

    =MAX(ABS(MIN(A1:A10)),MAX(A1:A10))*IF(ABS(MIN(A1:A10))>MAX(A1:10),-1,1)
    Last edited by Cutter; 02-09-2011 at 08:16 PM.

  5. #5
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,676

    Re: Returning greatest (absolute) value, including negatives

    Try

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

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  6. #6
    Registered User
    Join Date
    02-09-2011
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Returning greatest (absolute) value, including negatives

    The above works perfectly, thanks for the fast reply.

    Just one minor point, what if the cells were non-continguous? I keep getting syntax errors trying to pick individual cells, as oppose to A1:A10.

  7. #7
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,676

    Re: Returning greatest (absolute) value, including negatives

    How many cells? Is there a pattern like every other row or every 4 columns?

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Returning greatest (absolute) value, including negatives

    Another alternative

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

  9. #9
    Registered User
    Join Date
    02-09-2011
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Returning greatest (absolute) value, including negatives

    The number of cells varies from 2-3 (for the sake of the formula, assume its E2, J2, M2).

    I'm happy to pick them out myself, however, the syntax is apparently wrong, and it won't let me do that.

  10. #10
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,676

    Re: Returning greatest (absolute) value, including negatives

    Well, I think Cutter has cracked it - his version allows you to use a discontiguous range, i.e.

    =IF(ABS(MIN(E2,J2,M2))>MAX(E2,J2,M2),MIN(E2,J2,M2),MAX(E2,J2,M2))

    ....or my own variation on that.....

    =SUBTOTAL(4+(ABS(MIN(E2,J2,M2))>MAX(E2,J2,M2)),E2,J2,M2)

  11. #11
    Registered User
    Join Date
    02-09-2011
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Returning greatest (absolute) value, including negatives

    Thats it, thanks everyone.

  12. #12
    Registered User
    Join Date
    11-27-2013
    Location
    Korea
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Returning greatest (absolute) value, including negatives

    Quote Originally Posted by daddylonglegs View Post
    Try

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

    confirmed with CTRL+SHIFT+ENTER
    My apologies to bump this up.

    Hello daddylonglegs,
    Your provided formula did works well for getting the maximum values with signs.

    Can you please teach how to write this simply for VBA module use, example by using worksheetfunction or application.
    I will insert the VBA function to an existing module to get the answer at cell B1

    Cells(2, 1).Value = __________

    Thank you.

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    11,975

    Re: Returning greatest (absolute) value, including negatives

    @pilak,
    1. Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

    2. Don't quote whole posts -- it's just clutter. If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

    For normal conversational replies, try using the QUICK REPLY box below.
    Ben Van Johnson

  14. #14
    Registered User
    Join Date
    04-08-2020
    Location
    chennai
    MS-Off Ver
    16
    Posts
    1

    Re: Returning greatest (absolute) value, including negatives

    both the numbers are returning me exponential results. what to do?

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, Suffolk (England), but grew up in Sawley, Derbyshire
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2211 (Windows 11 22H2 64-bit)
    Posts
    65,383

    Re: Returning greatest (absolute) value, including negatives

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" to anyone who has offered you help in your thread. You can reward them by clicking on * Add Reputation below theur user name on the left, if you wish.


    Forum Rules (updated September 2018): please read them here.
    How to use the Power Query code you've been given: help here. More about the Power suite here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1