How do I find the closest number to a given number in an unsorted.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to find the first occurence of a number in an unsorted list (stock
prices by date). I need to be able to do this from within a formula. The
lookup functions and Match functions don't work because of the inability to
sort. Any help would be appreciated.
 
Hi
use
=VLOOKUP(lookup_value,A1:A100,1,FALSE)

or
=INDEX(A1:A100,MATCH(lookup_value,A1:A100,0))

if you're looking for an exact match. If you need a closest match try
the following array formula (entered with CTRL+SHIFT+ENTER):+
=INDEX(A1:A100,MATCH(MIN(ABS(A1:A100-lookup_value)),ABS(A1:A100-lookup_
value),0))
 
Re-read Help for LOOKUP and MATCH. They both have options for exact
matches with unsorted data.

Jerry
 
mpsfeldt said:
I need to find the first occurence of a number in an unsorted lis
(stock
prices by date). I need to be able to do this from within a formula.
The
lookup functions and Match functions don't work because of th
inability to
sort. Any help would be appreciated.

If you set the match type (range_lookup) to 0 or FALSE in the functio
(VLOOKUP, MATCH,...) you invoke, you would get what you want
 
Frank,
Thanks for the response. I accidently didn't finish my first sentence. It
should have said "I need to find the first occurence of a number in an
unsorted list
(stock prices by date) that is larger than a given threshold number.

Your response gives me the closest number to the threshold number but not
the first number. It's an elegant response though. If you have any thoughts
on getting to the first number though, I'd sure appreciate it.

Thanks again.

Mark Schoenfeldt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top