+ Reply to Thread
Results 1 to 10 of 10

Find the closest number

  1. #1
    Registered User
    Join Date
    10-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    16

    Find the closest number

    This may be easy but I'm missing it.

    I have a row (A1-M1) of numbers. I want to input a formula to find which number(s) in columns B1-M1 are the nearest, + or -, to the number in A1.

    As I say it's probably easy but if someone can give me an exmple formula for this that'd be great.

    Thanks.

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

    Re: Find the closest number

    Returning multiple numbers in one cell could prove difficult for a native formula

    In terms of returning the first closest match (should more than one exist)

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find the closest number

    EDIT: Nvm, that didn't work.
    Last edited by JBeaucaire; 10-20-2010 at 01:05 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    10-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Find the closest number

    Thanks for the reply and what you suggested does work but not in the way I wanted and it's my fault I didn't explain very well.

    I've attached a simplified example of the sheet I'm working on. A question is asked and I input the answer in one column (C) and the answers I have been given by tested individuals. There answers go in the columns D-J under their respective name and what I want to do is put formulas in columns K-Q that search columns D-J to find which answer is closest to the answer in C and populate the relevant cell with the value "1" (more than one candidate can be the closest). If the answer in K-Q is exactly the same as the answer in C then populate the cell with the value "2".

    Hope this makes sense.
    Attached Files Attached Files
    Last edited by xyba; 10-20-2010 at 01:31 PM.

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

    Re: Find the closest number

    My suggestion would be the following:

    Please Login or Register  to view this content.
    then

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Find the closest number

    These work perfectly. Thanks very much for the help.

  7. #7
    Registered User
    Join Date
    10-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Find the closest number

    Further to this query, what if the values input could be either text and/or numbers, what changes would I need to make to this code?

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

    Re: Find the closest number

    I think you would need to first clarify the requirements...

    If you mean "text input values" should be ignored (so as to prevent coercion errors etc...) then:

    Please Login or Register  to view this content.
    If on the other hand you're saying you want closest match to also work for text strings then that's a whole different ball game - and would warrant a new thread.
    (goes without saying that the logic used to determine "closest" match of "text" can vary hugely from one context to the next)
    Last edited by DonkeyOte; 10-21-2010 at 04:19 AM.

  9. #9
    Registered User
    Join Date
    10-20-2010
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Find the closest number

    Quote Originally Posted by DonkeyOte View Post
    I think you would need to first clarify the requirements...

    If you mean "text input values" should be ignored (so as to prevent coercion errors etc...) then...

    If on the other hand you're saying you want closest match to also work for text strings then that's a whole different ball game - and would warrant a new thread.
    Hi

    Yes I mean I want the closest match to work for text strings also.
    Last edited by DonkeyOte; 10-21-2010 at 04:21 AM. Reason: reduced quote to pertinent parts

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

    Re: Find the closest number

    New thread please - and you would need to provide a lot of examples illustrating how you intend to determine the "closest" match.

+ 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