+ Reply to Thread
Results 1 to 7 of 7

Find closest value in range with ascending then descending data

  1. #1
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Find closest value in range with ascending then descending data

    Hello,

    I'm not sure how to do this with Excel function. My data might look something like this:

    1
    2.3
    5
    12.5
    17
    20.1
    30.3
    20.7
    17.3
    12.7
    5.9
    2.9
    1.1

    Say I want to find the cell closest to 30. Normally, if my data was only in ascending ordering I'd use Indirect(address(match(30,A:A,1),1), but what I want to find the cell closest to 30 with data that ascends then descends? If I use the same formula, it just returns the last value?

    Thanks in advance, Natalie

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: Find closest value in range with ascending then descending data

    With 30 in D1, use this array formula:

    =INDEX(A1:A13,MATCH(MIN(ABS(A1:A13-D1)),ABS(A1:A13-D1),0))


    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Spammer
    Join Date
    01-08-2015
    Location
    Cali, Colombia
    MS-Off Ver
    365
    Posts
    302

    Re: Find closest value in range with ascending then descending data

    Hi, to both!

    Another option could be (NON - CSE):
    [D2] : =LOOKUP(,0/FREQUENCY(0,ABS(A1:A13-D1)),A1:A13)

    Check file. Blessings!
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: Find closest value in range with ascending then descending data

    Thanks Glenn!

    Why didn't you use D1 and not $D$1?

    I have it working for some columns and not others. I'll try to work it out for a bit first.

  5. #5
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: Find closest value in range with ascending then descending data

    Thanks Johnmpl, this also worked for me! I

  6. #6
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Re: Find closest value in range with ascending then descending data

    Oh, and I don't understand the purpose for the "0/"?

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,986

    Re: Find closest value in range with ascending then descending data

    I didn't $ any if the firmula because there wasn't any apparent need to copy the formula.

    You're welcome.



    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. macro ascending/descending
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-02-2016, 04:54 PM
  2. macro ascending/descending
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2016, 10:37 AM
  3. How do you do Ascending - Descending within same Code
    By Aeneren in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-31-2014, 09:18 PM
  4. [SOLVED] Sorting a group of data from ascending to descending
    By 11linc11 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-20-2013, 05:00 AM
  5. [SOLVED] Reverting data sort from ascending to descending
    By two.n.twenty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2012, 01:22 PM
  6. ascending - descending
    By Bonnie WLU in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-17-2009, 08:53 AM
  7. [SOLVED] Help on autofilter sort ascending and descending!
    By crapit in forum Excel General
    Replies: 2
    Last Post: 12-12-2005, 10:45 AM

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