+ Reply to Thread
Results 1 to 9 of 9

Returning adjacent value based on closest match to another cell value

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    United States
    MS-Off Ver
    Office 16 / 365
    Posts
    14

    Returning adjacent value based on closest match to another cell value

    Hi everyone,

    Have an otherwise-complicated tool that is referencing zip codes and performing many functions.

    I'm aiming to do the following now (please reference the attached Excel file): Based on a cell value in column I (auto-generated from column G), I want to reference anywhere in column C with that value. From those specified rows (will vary), I want to find the closest value to column H within column B and return the corresponding value from column A.

    If it's easier to follow the color coding, here that is: based on red (column I) that match those in column C, find the orange (column B) value that is closest to column H and return the corresponding yellow cell (column A).

    For this example, based on column I, looking for TX zips in columns A-C, it should return 77502 since code 82 is closer to code 85 than code 90.

    Sorry for any confusion. If there's any more info you would need, please let me know.

    Thanks,
    Attached Files Attached Files
    Last edited by yankeesrus07; 11-17-2016 at 05:22 PM.

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Returning adjacent value based on closest match to another cell value

    What if H2 was 87
    What if H2 was 88

    ?

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Returning adjacent value based on closest match to another cell value

    Play around with this and see if it will work for you...
    =INDEX($A$2:$A$6,MATCH(I2&H2,INDEX($C$2:$C$6&$B$2:$B$6,0))+1)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: Returning adjacent value based on closest match to another cell value

    @ Jonmo, I know my suggestion is not perfect, but perhaps it will do. I could probably refine a bit

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Returning adjacent value based on closest match to another cell value

    I don't know how it will deal with the non exact match between H2 and column B
    Last edited by Jonmo1; 11-17-2016 at 05:02 PM.

  6. #6
    Registered User
    Join Date
    11-09-2012
    Location
    United States
    MS-Off Ver
    Office 16 / 365
    Posts
    14

    Re: Returning adjacent value based on closest match to another cell value

    @ FDibbins, thank you for the great start to this syntax

    Just would need a tweak to it. Re: Jonmo, the cell values in column H are dependent upon the value in column G. For this test file, I've just input the values alone.

    So, J2 pulls over fine so long as H2 < B5. But instead, we're looking to find the closest value in general. So, if I were to put 86 in H2, it should return A5. Same with 87. But as soon as 88 is input, it should switch over to A6.

    Does that make sense? What kind of syntax would need to be adjusted to accommodate for that? Regarding instances where it's equidistant (referencing value 85 between 80 and 90), there is no preference there (so long as it chooses one of the column A values that correspond to either 80 or 90 in column B).
    Last edited by yankeesrus07; 11-17-2016 at 05:09 PM.

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Returning adjacent value based on closest match to another cell value

    Try this array formula entered with CTRL + SHIFT + ENTER

    =INDEX($A$2:$A$6,MATCH(MIN(IF($C$2:$C$6=$I$2,ABS($H$2-$B$2:$B$6),"")),ABS(IF($C$2:$C$6=$I$2,$H$2-$B$2:$B$6,9.99999999999999E+307)),0))

  8. #8
    Registered User
    Join Date
    11-09-2012
    Location
    United States
    MS-Off Ver
    Office 16 / 365
    Posts
    14

    Re: Returning adjacent value based on closest match to another cell value

    Initial tests are looking good! Thank you so much!

    If something wonky happens, I know where to go!

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Returning adjacent value based on closest match to another cell value

    You're welcome.

+ 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] Returning a list with constants based on adjacent cell
    By JYTS in forum Excel General
    Replies: 13
    Last Post: 12-07-2015, 10:02 AM
  2. Move cell based on closest match from list.
    By jeff p in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2014, 01:27 PM
  3. Returning a value based on a cell with a partial match
    By Backroomgeeza in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-16-2013, 04:21 AM
  4. Top N List based on 2 conditions & returning adjacent cell text
    By Kooey in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-26-2011, 11:58 AM
  5. vlookup returning the closest match down
    By kadams99 in forum Excel General
    Replies: 4
    Last Post: 12-08-2009, 08:00 PM
  6. [SOLVED] how do I insert a cell based on its match with an adjacent cell?
    By Gabbon in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-24-2006, 08:30 AM
  7. Replies: 0
    Last Post: 08-25-2005, 02:37 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