![]() |
Date Comparison in Code
Here is the actual code that causes this interesting
problem: If Sheets("Monitor").Cells(6, 5).Value Sheets ("Corrective Actions").Cells(6, 5).Value Then UserForm1.Show Both are date formatted fields as described below, yet it seems to be only looking at the time of day. Thanks for any further insight!! -----Original Message----- Having a problem with a date comparison... c1 = 9/21/04 9:00:00 AM d1 = 9/15/04 11:00:00 AM If date (c1) (d1) then UserForm1.Show This should show the form, but instead because 11 is greater than 9 it does not. And, when you reverse the formula is will show the form. If date (c1) < (d1) then UserForm1.Show Is there a setting or reclaration required? Thanks, Noel . |
Date Comparison in Code
On Mon, 4 Oct 2004 14:47:42 -0700, "nbs"
wrote: Here is the actual code that causes this interesting problem: If Sheets("Monitor").Cells(6, 5).Value Sheets ("Corrective Actions").Cells(6, 5).Value Then UserForm1.Show Both are date formatted fields as described below, yet it seems to be only looking at the time of day. Thanks for any further insight!! You wrote that you checked the formatting of the fields but you did write that you checked the actual contents of the fields. Even if the fields are formatted as date, it is still possible for the contents of one (or both) of the fields to be TEXT. See what =ISTEXT(cell_ref) shows. --ron |
Date Comparison in Code
Another way to check is to do
Sub AAAA() Dim vVal1 As Variant, vVal2 As Variant Dim msg As String vVal1 = Sheets("Monitor").Cells(6, 5).Value vVal2 = Sheets("Corrective Actions").Cells(6, 5).Value msg = TypeName(vVal1) & " " & vVal1 _ & vbNewLine & TypeName(vVal2) & " " & vVal2 _ & vbNewLine & "Monitor Corrective: " & (vVal2 vVal2) MsgBox msg End Sub Suggest that you will get something like: Date 9/21/04 9:00:00 AM String 9/15/04 11:00:00 AM Monitor Corrective: False -- Regards, Tom Ogilvy "nbs" wrote in message ... Here is the actual code that causes this interesting problem: If Sheets("Monitor").Cells(6, 5).Value Sheets ("Corrective Actions").Cells(6, 5).Value Then UserForm1.Show Both are date formatted fields as described below, yet it seems to be only looking at the time of day. Thanks for any further insight!! -----Original Message----- Having a problem with a date comparison... c1 = 9/21/04 9:00:00 AM d1 = 9/15/04 11:00:00 AM If date (c1) (d1) then UserForm1.Show This should show the form, but instead because 11 is greater than 9 it does not. And, when you reverse the formula is will show the form. If date (c1) < (d1) then UserForm1.Show Is there a setting or reclaration required? Thanks, Noel . |
All times are GMT +1. The time now is 02:09 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com