![]() |
DateSerial vs Date??
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 |
DateSerial vs Date??
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] On Mon, 30 Nov 2009 16:32:35 -0500, "Otto Moehrbach" wrote: 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 |
DateSerial vs Date??
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" wrote in message ... 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] On Mon, 30 Nov 2009 16:32:35 -0500, "Otto Moehrbach" wrote: 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 |
All times are GMT +1. The time now is 10:06 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com