+ Reply to Thread
Results 1 to 9 of 9

Find closest value(s) location in range

Hybrid View

  1. #1
    Registered User
    Join Date
    12-31-2016
    Location
    israel
    MS-Off Ver
    2016
    Posts
    36

    Find closest value(s) location in range

    Hi
    I have a data set of numbers.
    Range is A1:SH602
    I am trying to set a formula that will return:
    The cells in that range that holds matching value to number in cell A607 (there may be more than one cell with matching value)
    In case there are no matching cells, return the cells with closest value.
    I tried using this array formula:
    =INDEX(A1:SH602,MATCH(MIN(ABS(A1:SH602-A607)),ABS(A1:SH602-A607),0))
    But it returns an error
    Thanks

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,598

    Re: Find closest value(s) location in range

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,172

    Re: Find closest value(s) location in range

    Try this

    =AGGREGATE(15,6,A1:SH602/(AGGREGATE(15,6,ABS(A1:SH602-A607),1)=ABS(A1:SH602-A607)),1)

  4. #4
    Registered User
    Join Date
    12-31-2016
    Location
    israel
    MS-Off Ver
    2016
    Posts
    36

    Re: Find closest value(s) location in range

    Thanks!
    Look like this formula returns the value itself, not the cell reference . I am looking for the cell reference

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,172

    Re: Find closest value(s) location in range

    Use ADDRESS:

    =ADDRESS(INT(AGGREGATE(15,6,(ROW(A1:SH602)*10000+COLUMN(A1:SH602))/(AGGREGATE(15,6,ABS(A1:SH602-A607),1)=ABS(A1:SH602-A607)),1)/10000),
    MOD(AGGREGATE(15,6,(ROW(A1:SH602)*10000+COLUMN(A1:SH602))/(AGGREGATE(15,6,ABS(A1:SH602-A607),1)=ABS(A1:SH602-A607)),1),10000),4)

  6. #6
    Registered User
    Join Date
    12-31-2016
    Location
    israel
    MS-Off Ver
    2016
    Posts
    36

    Re: Find closest value(s) location in range

    Great!
    Thanks a lot, this formula returns only the first cell reference, how can i get all the cells that match the criteria?

  7. #7
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Find closest value(s) location in range

    Are you still using Excel 2016? Or is your system updated in the meantime?
    Last edited by HansDouwe; 12-05-2022 at 08:49 AM.

  8. #8
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Find closest value(s) location in range

    If you are updated to Excel 365, please try
    Formula: copy to clipboard
    =LET(t,A1:SH602,a,MAKEARRAY(ROWS(t),COLUMNS(t),LAMBDA(x,y,IF(ABS(A607-INDEX(t,x,y))=MIN(MAP(t,LAMBDA(x,ABS(x-A607)))),1000*x+y))),REDUCE("",a,LAMBDA(x,y,IF(y,TEXTJOIN(", ",,x,ADDRESS(y/1000,MOD(y,1000))),x))))
    A smaller example of this formula is included in the attached workbook.
    Attached Files Attached Files

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Find closest value(s) location in range

    Here is a simplification of my formula in the previous post:

    If you are updated to Excel 365, please try
    Formula: copy to clipboard
    =LET(t,A1:SH602,a,MAKEARRAY(ROWS(t),COLUMNS(t),LAMBDA(x,y,IF(ABS(A607-INDEX(t,x,y))=MIN(MAP(t,LAMBDA(x,ABS(x-A607)))),ADDRESS(x,y,4),""))),TEXTJOIN(", ",,a))
    A smaller example of this formula is included in the attached workbook.
    Attached Files Attached Files

+ 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. [SOLVED] Finding closest location to a point, as well as the next two closest.
    By SolarDesign in forum Excel General
    Replies: 11
    Last Post: 11-11-2021, 02:39 AM
  2. Macro to find closest X workers to a location based on long/lat
    By tylerfring in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2021, 08:38 AM
  3. [SOLVED] Find closest value from Range
    By ISMI in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-06-2020, 02:29 PM
  4. How to find the closest number in range
    By mariab1 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-11-2015, 10:52 AM
  5. Replies: 13
    Last Post: 03-27-2012, 05:12 PM
  6. find closest date (number) in a range
    By wamp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-23-2010, 01:50 PM
  7. Find closest value in a range
    By msbing916 in forum Excel General
    Replies: 2
    Last Post: 11-19-2009, 11:24 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