Thread: Check date
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Check date

Rick,
Maybe all these years of one-liners in VB you have missed your true calling
of Excel worksheet formulae. <g

NickHK

"Rick Rothstein (MVP - VB)" wrote in
message ...
Sorry, *it* is refer to the date store in G3. First of all, ignore the
leap year. I just concern on MONDAY only since the vba code only check

on
the cell that contains this formula on Monday. I would like to get the
result of, if the date in G3 is the first Monday on or after the 29th

of
each month, return True, other Mondays return false.


Assuming you mean that March 1st would qualify as the first day after

the
imaginary February 29th of a non-leap year, then the following formula
will return True if the date in G3 falls is a first Monday following the
29th of a month...


=(G3=DATE(YEAR(G3),MONTH(G3)-(DAY(G3)<7),28)+8-WEEKDAY(DATE(YEAR(G3),MONTH(G
3)-(DAY(G3)<7),28)-1))

Maybe that statement above needs a little clarification (to make sure I
actually calculated what you wanted). If the date in G3 falls within the
first week of its month, then the date it is compared to is the first
Monday following the 29th of the previous month. Take June 4, 2007 as an
example... the above formula returns True for if G3 contains the date

June
4, 2007 because that date is the first Monday that follows May 29, 2007.
Take September 29, 2008 as another example. If G3 contains this date,

the
above formula also returns True because that date falls on a Monday.


While this is not an answer to the question you asked, I thought you might
be interested in the complimentary functional code... given a date in G3,
what is the date of the first Monday on or after the 29th of G3's month?

The
answer is...

=36+G3-DAY(G3)-WEEKDAY(G3-DAY(G3)-1)

You can't use this function directly because it uses G3's month to

calculate
from. For example, if you set June 4, 2007 into G3, it won't return June

4,
2007 even though that date is a first Monday on or after a 29th of some
month because it doesn't know to look at the previous month. As I said, I
just though you might find the simplicity of the function interesting.

Rick