+ Reply to Thread
Results 1 to 9 of 9

lookup or match - Return nearest match

  1. #1
    Registered User
    Join Date
    03-07-2008
    Posts
    3

    Thumbs down advice : What functions do i use to do ?

    Hi

    i wonder if someone can tell me what function or group of functions i need to look at to achieve the following

    i have a list in a range

    20
    33
    45
    68
    74

    i then enter in a cell a value to use as a lookup

    example 30

    i need to do two things

    look up the next largest number available from the range in this case it would be 33 and return that


    if i enter 33 and since 33 exists in the list i need it jump to the next largest so returning 45 in this case.

    i presume i can use two if statements but dont know the best way to work out the offset of moving to the next largest value and if i should use index and match or vlookup etc.

    just looking for a pointer for the best way of doing it and also a bit of explanation of how i can use an offset to select the cell next to it or below it

    Thanks a alot
    IT Support
    Bradrail Blinds and Awnings - Nottingham
    http://www.bradrail.co.uk

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444
    Hi,

    =INDEX(A1:A5,MATCH(A8,A1:A5,1)+1)

    if your list is A1:A5 and your look up cell is A8

    index returns the content of a cell in a range, eg

    =INDEX(A1:C5,2,2) returns the second cell in and down in the array A1:C5

    match identifies the position of a value in an array.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    03-07-2008
    Posts
    3

    lookup or match - Return nearest match

    Hi there.

    I looking for some help with choosing the best functions to do this simple task.

    I have a range of numbers

    20
    34
    63
    54

    So the users enters a number ie 25

    in which i need to do a lookup or match for ... which i think i have got the basics off i need to test two options to return the result

    if i select 25 i need to pick the largest number about it so in this case it will be 34 and return that

    if the number exist in the list ie the user has entered 63 which is available to return that value

    I tried the vlookup but dont know how to put the offset to move to the next higher value.

    I dont know if that is the best way of doing it. and would rather learn a way which i can you to apply various offsets in columns and rows

    Well i will look forward to hearing what people suggest.

    Many thanks

    Devo
    Last edited by VBA Noob; 03-08-2008 at 05:44 AM.

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

  5. #5
    Registered User
    Join Date
    03-07-2008
    Posts
    3

    sweep - thank you

    sweep thank you very much for your reply..

    sorry about the double post lol. i couldnt find my first post but did have a bit of a problem posting it .. .. ooops computer glitch at my end..

    but appreciate the reply..

    thank you

    Nick Calladine
    Blinds and Awnings in Nottingham

  6. #6
    Registered User
    Join Date
    07-05-2012
    Location
    BAngkok, Thailand
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: lookup or match - Return nearest match - Need additional help please

    Suppose the numbers change to
    20
    33
    45
    68
    74
    25
    38
    32

    and the look up cell is B1 and it contains 22

    the code

    =INDEX(A1:A8,MATCH(B1,A1:A8,1)+1)

    does not seem to work because it returns 33 while the next larger number should be 25

    Can anyone help please?
    Will this code work if the numbers used are dates instead of general numbers?
    Also what should I do if suppose there is a blank row between the values.

    Thank you in advance.
    Chris

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: lookup or match - Return nearest match

    ckorp,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  8. #8
    Registered User
    Join Date
    07-05-2012
    Location
    BAngkok, Thailand
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: lookup or match - Return nearest match

    Sorry WIll try to do that. It actually is a direct continuation of this question becaue the answer provided did not correctly answer the original question.

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

    Re: lookup or match - Return nearest match

    Answer was correct. In your post we'll explain why is different now
    Last edited by zbor; 07-05-2012 at 07:52 AM.

+ 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