Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
nbs nbs is offline
external usenet poster
 
Posts: 7
Default Date Comparison in Code

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date Comparison in Code

If the dates are stored as dates, then from the immediate window

? Range("C1").Value
9/21/2004 9:00:00 AM
? Range("D1").Value
9/15/2004 11:00:00 AM
? range("C1") Range("D1")
True

even as Strings

? "9/21/2004 9:00:00 AM" "9/15/2004 11:00:00 AM"
True

But if I convert the first to a date and compare to the second as a string
I get your result.

? cdate("9/15/2004 11:00:00 AM") "9/15/2004 11:00:00 AM"
False

Your code as shown wouldn't be correct in either Excel as formulas or VBA as
code, so it is hard to say what you are doing, but with Date only prefacing
the first value, it doesn't appear correct technically or conceptually.

--
Regards,
Tom Ogilvy



"nbs" wrote in 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Date Comparison in Code

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
-----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
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF(AND with date comparison PSU35 Excel Worksheet Functions 4 October 27th 09 03:14 PM
Date Comparison Vic Excel Discussion (Misc queries) 1 October 22nd 09 03:18 PM
Date comparison adimar Excel Worksheet Functions 14 February 3rd 08 06:44 PM
Date comparison TomD Excel Discussion (Misc queries) 4 February 20th 07 10:37 PM
Date comparison Darkdrew Excel Worksheet Functions 7 March 23rd 06 04:22 PM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"