DateSerial vs Date??

O

Otto Moehrbach

Excel 2007 Win 7 64-bit
The range rColJ is a string of cells containing dates, the largest of which
is 6 Dec 09. That string of dates was not changed in the following
troubleshooting procedure.
I want to know if the maximum date in rColJ >= 1 Dec 09. My code is:
If Application.Max(rColJ)>DateSerial (2009, 12, 1) Then....
The argument is False, even though 6 Dec 09 is in that range.
I changed that line of code and substituted the numerical value of 6 Dec 09
(38686) for the DateSerial expression:
If Application.Max(rColJ)>38686 Then....
That argument is True.
What mistake did I make in using the DateSerial VBA function?
Thanks for your time. Otto
 
C

Chip Pearson

If Application.Max(rColJ)>DateSerial (2009, 12, 1) Then....

If the date 1-December-2009 is the maximum date in rColj, the
condtional will be false because it equals DateSerial(2009,12,1) and
your test if for "greater than", not "greater than or equal to".
Change the ">" to ">=" if you want to include equality.
If Application.Max(rColJ)>38686 Then....

The value 38686 is equivalent to 30-Nov-2005, which is certainly less
than 1-Dec-2009.

Think carefully about the logic you need and then write code
accordingly.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 
O

Otto Moehrbach

Chip
I did test for >= in my code, and the maximum date in rColJ was 6 Dec
09, not 1 Dec 09 (see my post). I did have the number, 38686, wrong. It
should have been 40148. Thanks for your time. Otto

Chip Pearson said:
If Application.Max(rColJ)>DateSerial (2009, 12, 1) Then....

If the date 1-December-2009 is the maximum date in rColj, the
condtional will be false because it equals DateSerial(2009,12,1) and
your test if for "greater than", not "greater than or equal to".
Change the ">" to ">=" if you want to include equality.
If Application.Max(rColJ)>38686 Then....

The value 38686 is equivalent to 30-Nov-2005, which is certainly less
than 1-Dec-2009.

Think carefully about the logic you need and then write code
accordingly.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




Excel 2007 Win 7 64-bit
The range rColJ is a string of cells containing dates, the largest of
which
is 6 Dec 09. That string of dates was not changed in the following
troubleshooting procedure.
I want to know if the maximum date in rColJ >= 1 Dec 09. My code is:
If Application.Max(rColJ)>DateSerial (2009, 12, 1) Then....
The argument is False, even though 6 Dec 09 is in that range.
I changed that line of code and substituted the numerical value of 6 Dec
09
(38686) for the DateSerial expression:
If Application.Max(rColJ)>38686 Then....
That argument is True.
What mistake did I make in using the DateSerial VBA function?
Thanks for your time. Otto
 

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

Top