+ Reply to Thread
Results 1 to 9 of 9

VLOOKUP value closest to

  1. #1
    Registered User
    Join Date
    07-20-2009
    Location
    philly
    MS-Off Ver
    Excel 2003
    Posts
    32

    VLOOKUP value closest to

    I have a row of data that I want to grab based on a single cell of data.

    say my cell A1 = 5

    I then have many rows of data in another worksheet:

    8 | 100
    7 | 93
    6 | 73
    9 | 32

    since there is no value for "5" in any of the rows, I want to return the closest value to 5 (6). how do i do this?

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VLOOKUP value closest to

    First you must sort your left column in ascending order.
    One way is to add in first column of the table 0 and 73 ( or =B3) wich will give you 73 for all positive values that you enter in A1

    =VLOOKUP(A1;$A$2:$B$6;2;TRUE)

    Please Login or Register  to view this content.
    Last edited by zbor; 09-10-2009 at 09:35 AM.

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: VLOOKUP value closest to

    What do you mean by closest... over or under or must be over....

    Can the lookup sheet be sorted?
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VLOOKUP value closest to

    If as implied data is not sorted, criteria is in A1 on sheet1, values in Sheet2!A1:A4 then:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-20-2009
    Location
    philly
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: VLOOKUP value closest to

    the data isnt sorted. when i mean closest, it can be over or under. keep in mind that these arent necessarily whole numbers. it could be:

    6.1
    6.2
    5.1
    3.3

    in this case i would want 5.1

    it could be

    4.4
    3.3
    3.2
    4.6
    5.6

    in this case i would want 4.6

  6. #6
    Registered User
    Join Date
    07-20-2009
    Location
    philly
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: VLOOKUP value closest to

    donkey - that works. thanks

  7. #7
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: VLOOKUP value closest to

    In that case your title does not comply Rule 1:

    1. Your post title should accurately and concisely describe your problem, not your anticipated solution.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VLOOKUP value closest to

    Quote Originally Posted by dch27 View Post
    donkey - that works. thanks
    You mention VLOOKUP which would imply that perhaps you want to return the associated value - ie return B where A is closest match, you can alter the INDEX range to return the value from whichever column you wish, eg:

    Please Login or Register  to view this content.
    The Match needs to be conducted against A of course but the INDEX can be whichever column you prefer - alter as required.

  9. #9
    Registered User
    Join Date
    07-20-2009
    Location
    philly
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: VLOOKUP value closest to

    another question:

    because of the array that I am referencing is dynamic, sometimes the cells will say #N/A, and sometimes they dont. If at any time they do, Donkey's equation doesnt work because if these #N/A's. is there a way i can fix that.

+ Reply to 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