+ Reply to Thread
Results 1 to 11 of 11

Match to nearest in range, then return value of a different cell.

  1. #1
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Match to nearest in range, then return value of a different cell.

    Hey all, got a question for our Excel and GoogleDocs gurus out there.

    I need to achieve the following in a GoogleDocs worksheet:

    1. Take the value from a specific cell.
    2. Compare it to a range fo values across a horizontal row of cells.
    3. Confirm which number specified the original value is closest to.
    4. Return a code from a separate horizontal row of cells that indicates which specified range index the original number was correlated to.

    I'll be the first to admit I'm a bit of an Excel noob, so I apologise if this is basic - I'm badly dyslexic and I just can't quite wrap my head around how to get these four steps to happen in one move.

    I've attempted to dad the workbook itself, but in the interest of quick clarity, here's a screenshot with the values I need to work with in red.

    Nay help greatly appreciated!

    PDO question.PNG

    LiamHH

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Match to nearest in range, then return value of a different cell.

    I don't know about GoogleDocs, but the closest function is probably HLOOKUP, but some adjustments would need to be made...

    First, HLOOKUP doesn't find the closest value, but it does find the value less than or equal to your key value. For example, using your table above, for a key value of 15, it find the 6.375 since it is less than 15 and the 19.125 cell is greater. Another example, a key value of 100 would find the 95.625.

    Second, HLOOKUP must have the range of values as the top row of its table. So, you would have to put the 6.375, 19.125, etc. as the top row of your table. Then you tell it which row in the table you want the value to be.

    Best to check out a webpage: https://support.office.com/en-us/art...5-e1ad662ed95f
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Re: Match to nearest in range, then return value of a different cell.

    Hi Pauley,

    Thanks for your reply. If it's not possible to od this in one step, would it be possible in multiple? Something like this:

    1. Row recording the index of the row of scores (eg, row 1 shows index, not just a number indicating position)
    2. Column which searches which values for closest and returns closest value (eg 'search row 3. Return number from row 3 which is closest to (value in G5))
    3. In the new column, for closest value, return index x

    This might be less streamlined, but in this context that's acceptable. Could you please advise what, if any forumuals might achieve this?

    Illustrated again for calrity:

    PDO question 2.png


    Thanks again
    Last edited by LiamHH; 05-27-2020 at 09:36 PM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Match to nearest in range, then return value of a different cell.

    Someone this morning asked almost the exact same question https://www.excelforum.com/excel-for...from-data.html There data is vertical where yours is horizontal, but, otherwise, either strategy we suggested should work for your data as well.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Re: Match to nearest in range, then return value of a different cell.

    Quote Originally Posted by MrShorty View Post
    Someone this morning asked almost the exact same question ... There data is vertical where yours is horizontal, but, otherwise, either strategy we suggested should work for your data as well.
    Thank you! I'll give it a shot

  6. #6
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Re: Match to nearest in range, then return value of a different cell.

    Hi guys,

    I had a look at the formulas provided by Fluff31 for the question you linked me to, Mr Shorty. I changed my data set to vertical, and omitted the part about TODAY as I have no need for dates.

    My current attempt at a formula reads: =INDEX(C4:C45,MATCH(MIN(ABS(-C4:C45),ABS(-C4:C45),0)))

    The error I get is that MATCH expects more than one argument - do I need to put a MAX in here somewhere?

    Thanks again.

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

    Re: Match to nearest in range, then return value of a different cell.

    There are instructions at the top of the page explaining how to attach your sample workbook. You won't yet be able to post a link to your sheet - you'll need a few more posts for that, but if you want to post it without the https bit, I can convert it to a link for you, however we prefer attachments here (obviously converted to Excel).
    Ali


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

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Re: Match to nearest in range, then return value of a different cell.

    I did try this originally and got an error - it may have been a dyslexia issue when specifying file type, sorry. I'll try again to attach it to this post, as well as another pic.

    Basically, I need a formula htat compares the values in N4 to the value range B4:B45, finds the closest match, and returns the relative value from C4:C45 into P4. I've made the backgrounds grey to illustrate.

    Attachment 679865

    As I mentioned, my current formula is =INDEX(C4:C45,MATCH(MIN(ABS(-C4:C45),ABS(-C4:C45),0))) and it says I'm missing na argument in it. Any help always appreciated!

    - Liam.
    Attached Files Attached Files
    Last edited by AliGW; 05-28-2020 at 07:37 AM. Reason: Please don't quote unnecessarily!

  9. #9
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Match to nearest in range, then return value of a different cell.

    The TODAY() element was crucial as it was finding the date closest to today. You need to replace TODAY() with the number you want to get closest to. You then had a parentheses error and I think you were pulling from the wrong range for your answer.
    I think this is what you want for your O column: =INDEX($B$4:$B$45,MATCH(MIN(ABS(N4-$B$4:$B$45)),ABS(N4-$B$4:$B$45),0))
    This will work for your P column: =INDEX($C$4:$C$45,MATCH(MIN(ABS(N4-$B$4:$B$45)),ABS(N4-$B$4:$B$45),0))

    You need to enter these with control-shift-enter. You can then drag the formula down.

  10. #10
    Registered User
    Join Date
    05-27-2020
    Location
    NSW, Australia
    MS-Off Ver
    Various
    Posts
    6

    Re: Match to nearest in range, then return value of a different cell.

    Hi Pauley, thanks again for your support - unfortunately I couldn't make this play in Google Docs spreadsheets. I'm going to keep tinkering around - I may have to just define an additional column with the halfway point between each PDO bracket, and just "if value is in here, return x. If value is in here, return y.'' to get around the closest-to problem in Google Docs.

    Thanks to everyone for your responses! I'll tel you know if I crack it.

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: Match to nearest in range, then return value of a different cell.

    The formula suggested earlier for P4 does work in Google Sheets:

    =index($C$4:$C$45,match(min(ABS(N4-$B$4:$B$45)),ABS(N4-$B$4:$B$45),0))
    Rory

+ 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] Match data from one cell to a range on another worksheet and return value
    By Ninja79 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-08-2017, 04:12 PM
  2. [SOLVED] INDEX/MATCH generates incorrect result by referencng nearest cell if match not found
    By aglawrence in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-29-2017, 08:59 AM
  3. [SOLVED] 2 Column Look Up / Match - Return Item on or to the nearest date
    By DHHM in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2016, 06:55 AM
  4. [SOLVED] reference date time range, return the value into all cell that match datetime range
    By Jarvco13 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-22-2013, 10:39 PM
  5. [SOLVED] Compare strings for match in separate worksheet and return nearest future date
    By kungfood in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2012, 05:19 PM
  6. lookup or match - Return nearest match
    By devouk in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-05-2012, 06:11 AM
  7. Return the nearest cell above that isn't 0
    By nofzinger in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-18-2009, 10:29 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