+ Reply to Thread
Results 1 to 6 of 6

VBA Find Closest value w/o going over

  1. #1
    Registered User
    Join Date
    07-19-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2007
    Posts
    12

    VBA Find Closest value w/o going over

    Hello. I am looking for a way to determine the closest value in list B compared to values in list A. Neither List A or List B have unique identifiers. The values in column C needs to be the closest match to list B without going over. After endless attempts to solve this issue with excel functions, it seems like vba is going to be the best option.

    I have this macro that I am trying to tweak but I am not having any luck. Can somebody help me with this code? It needs to match based on columns A & columns H. I also need this code to loop through all of the values in list A.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: VBA Find Closest value w/o going over

    Can you just confirm the test data youve shown please?

    You say "The values in column C needs to be the closest match to list B without going over." however your test data shows Value of 19, Closest Value = 19.2, Value = 26.2, Closest Value = 55?
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    07-19-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Find Closest value w/o going over

    Thanks for the correction. Sorry, I should have done a better job with the test data. It was manully populated.

    List A
    AA Value = 19, Closest AA Value determined from List B by VBA Code = 18
    AA Value = 26.2, Closest AA Value determined from List B by VBA Code = 22
    AAL Value = 33.3, Closest AAL Value determined from List B by VBA Code = 32
    AAL Value = 38.3, Closest AAL Value determined from List B by VBA Code = 35



    List B
    AA = 18
    AA = 15
    AA = 22
    AA = 55
    AA = 19.2
    AAL = 18.5
    AAL = 32
    AAL = 35
    AAL = 28
    AAL = 44
    AAL = 41

    Quote Originally Posted by pjwhitfield View Post
    Can you just confirm the test data youve shown please?

    You say "The values in column C needs to be the closest match to list B without going over." however your test data shows Value of 19, Closest Value = 19.2, Value = 26.2, Closest Value = 55?
    Last edited by alrichar; 09-15-2015 at 10:52 AM.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: VBA Find Closest value w/o going over

    Ive finally written my first Array Function! Enter this using Ctrl+Shift+Enter

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: VBA Find Closest value w/o going over

    However, this returns values less than the original (which matches the requirements) but not your amended examples?

    Are you actually looking for items greater than the original value?

  6. #6
    Registered User
    Join Date
    07-19-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Find Closest value w/o going over

    Quote Originally Posted by pjwhitfield View Post
    However, this returns values less than the original (which matches the requirements) but not your amended examples?

    Are you actually looking for items greater than the original value?

    Please Login or Register  to view this content.


    Works perfectly. This is a lot easier than using a macro. Thanks for the help!

+ 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] How to find a value in a column that is closest to a given value
    By luv2glyd in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-10-2014, 06:37 PM
  2. [SOLVED] VBA Function to find closest value in row
    By masterell in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2013, 07:41 AM
  3. [SOLVED] Find closest values to a given value?
    By SneakyPiglet in forum Excel General
    Replies: 4
    Last Post: 04-23-2013, 08:49 AM
  4. [SOLVED] How to find the a value closest to a given value
    By BNCOXUK in forum Excel General
    Replies: 2
    Last Post: 02-15-2013, 06:12 AM
  5. Find the closest number
    By xyba in forum Excel General
    Replies: 9
    Last Post: 10-21-2010, 04:20 AM
  6. Using Find method to find the closest value.
    By Yappa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2008, 07:59 AM
  7. Find closest value
    By Arne Hegefors in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2006, 10:05 PM

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