+ Reply to Thread
Results 1 to 5 of 5

How can I match a random number with closest number from sequence?

  1. #1
    matt
    Guest

    How can I match a random number with closest number from sequence?

    For instance, if I have the following list (my list is 255 numbers long):
    A B
    ..7 Red
    1.2 Orange
    2.6 Brown
    3.5 Grey
    4.3 Yellow
    5.5 Red Orange

    and I enter 3.2 into C1, I would like for d1 to return 3.5 (the closest
    number to 3.2 from sequence). That's the main thing (remember I have 255 of
    these and I think excel only lets you nest 7 if's)

    Once the correct match is match, I would also like to display the color it
    is associated with (each of the 255 combinations has its own color)

    So, after it finds the 3.5 match from the 3.2 input, I would like another
    cell to display Grey.

    As another example, an input of 5.0 would return 5.5 and Red Orange.

    Thanks for the help.


  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Here's one way

    =INDIRECT(ADDRESS(ROW(A1:A6)+MATCH(MIN(ABS(C1-A1:A6)),ABS(C1-A1:A6),0)-1,COLUMN(A1:A6)+1))

    VBA Noob

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Sorry, should of said it's an array formula so need to enter with

    Ctrl + Shift + Enter

    VBA Noob

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Try this formula

    =INDEX(B1:B255,MATCH(MIN(ABS(C1-A1:A255)),ABS(C1-A1:A55),0))

    confirmed with CTRL+SHIFT+ENTER

  5. #5
    matt
    Guest

    Re: How can I match a random number with closest number from seque

    Thanks for the help! Both of these methods worked perfectly.

+ 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