Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Closest-to function

Is there a VBA function that sorts through a number of cells containing numbers that returns the cell closest to a certain value? For instance, in a column of numbers, I would like to find the cell containing the number closest to 20. The column may or may not contain 20 as a value.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default Closest-to function

"davidoo2005" wrote...
Is there a VBA function that sorts through a number of cells
containing numbers that returns the cell closest to a certain
value? For instance, in a column of numbers, I would like to
find the cell containing the number closest to 20. The column
may or may not contain 20 as a value.


In a worksheet the usual approach would be to use the array formula

=MATCH(MIN(ABS(Range-Target)),ABS(Range-Target),0)

You could replace Range and Target in the formula above with your own
values, then feed the resulting string to Evaluate. The result would be the
index in Range at which the first (topmost or leftmost) of possibly many
closest value to Target is found.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Lookup to Find Closest Date and Next Closest Date [email protected] Excel Worksheet Functions 7 November 7th 07 03:04 AM
closest match [email protected] Excel Worksheet Functions 4 June 11th 06 02:30 PM
Calculate the closest day Jim Excel Worksheet Functions 3 January 15th 06 01:40 AM
Function to find closest to 0 (including neg #'s) in cloumn Dante Excel Discussion (Misc queries) 9 October 13th 05 05:39 AM
what's the closest think to an "average if" function? Flutie99 Excel Worksheet Functions 2 May 28th 05 12:39 AM


All times are GMT +1. The time now is 11:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"