View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Arne Hegefors Arne Hegefors is offline
external usenet poster
 
Posts: 244
Default Find closest value


Hello! I have a small problem that I do not know exactly how to solve. I
have a macro that that searches a list in Excel for a certain date e.g.
2006-02-14. The date is stored in the array strSlutDatumArray(1). I look
using rng(1).Offset(j, 0) (never mind that but it just loops down in a list).
I apply this code on many lists. Almost all lists consist of dates based on a
5 day week. However some lists only contain one date per week.

Assume that I am searching for the date 2006-01-10. The lists contain only 1
date per week. I want to somehow check so that I choose the date closest to
2006-01-10 in the list. Assume that the list looks like:
2006-01-01
2006-01-08
2006-01-15

Then I want to stop my search at the date closest to 2006-01-10, i.e.
2006-01-08. Can anyone help me with how to do that? Any help is very much
appreciated! Thanks a lot in advance!

The code I am using for searching the list is:

Do Until IsEmpty(rng(1).Offset(j, 0)) = True Or rng(1).Offset(j, 0).text =
strSlutDatumArray(1) = True
j = j + 1
Loop