Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Compare value to array of values, "best fit" (closest without going over, e.g. price is right)
I have an array of values [CompareArray(1 to 10)] that holds 10 numbers in
order of size, e.g.: (4124, 8251, 15925, 52192, 248273, etc.) I pull a number from a worksheet using VBA, for example, 131827 I want to compare that number against the existing array, and determine the placement based on the rule that it has to be larger than the previous number, and smaller than (or equal to) the larger number. so in the above example; (4124, 8251, 15925, 52192, 248273, etc.) ^ 131827 it would return (position/integer) 5 because that would represent the value/bucket in the main array where it fits. I have accomplished this with a loop, where I compare the number against each successive pairs of numbers, but that doesn't seem very eloquent, and I suspect there is a _faster_ way to do this (I'll be doing thousands of these). What I have now is (something like): For i = 1 to 9 if NewNumber (CompareArray(i)) and NewNumber <(CompareArray(i+1) then FoundIt = i end if Next What is the best way to compare directly to the array values, as a whole, instead of one pair at a time? Thanks, Keith -- The enclosed questions or comments are entirely mine and don't represent the thoughts, views, or policy of my employer. Any errors or omissions are my own. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Compare two worksheets with "contains" and not "exact" values | Excel Worksheet Functions | |||
"Type mismatch" when I try to fill an Array variable with "+" | Excel Discussion (Misc queries) | |||
Compare to a range of values using "from/to" | Excel Discussion (Misc queries) | |||
Changing "returned" values from "0" to "blank" | Excel Worksheet Functions | |||
compare ranges in different workbooks and copy "not matching values" at bottom of range 1 | Excel Programming |