Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default comparing dates

I'm trying to test for a specific date.
If todays date is greater than the date in cell A1
then complete the action, else, show the message "Unable to ..."
but unless I use < the comparison does not work. The code
does not run. Why is this?
The following runs:
-------------
Dim dt as Date
dt = .Cells (1,1)
If date1 < Now() Then
MsgBox "Unable to.."
------------
This does not run:

Dim dt as Date
dt = .Cells (1,1)
If dt Now() Then
MsgBox "Unable to.."
----------
Thanks in advance.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default comparing dates

In your 2nd example you're using different names for your variables. dt vs.
date1

Always use Option Explicit.
You can use Date instead of Now which returns just date (not time hh:mm:ss)

Sub test()
Dim dtm As Date

dtm = Cells(1, 1).Value
If dtm <= Date Then
MsgBox "Unable to run"
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Myriam" wrote in message
...
I'm trying to test for a specific date.
If todays date is greater than the date in cell A1
then complete the action, else, show the message "Unable to ..."
but unless I use < the comparison does not work. The code
does not run. Why is this?
The following runs:
-------------
Dim dt as Date
dt = .Cells (1,1)
If date1 < Now() Then
MsgBox "Unable to.."
------------
This does not run:

Dim dt as Date
dt = .Cells (1,1)
If dt Now() Then
MsgBox "Unable to.."
----------
Thanks in advance.






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 303
Default comparing dates

This works.........

Sub check()
Dim dt As Date
dt = Cells(1, 1)
If dt Now() Then
MsgBox "Unable to.."
End If
End Sub

Regards
Bill K

"Myriam" wrote in message
...
I'm trying to test for a specific date.
If todays date is greater than the date in cell A1
then complete the action, else, show the message "Unable to ..."
but unless I use < the comparison does not work. The code
does not run. Why is this?
The following runs:
-------------
Dim dt as Date
dt = .Cells (1,1)
If date1 < Now() Then
MsgBox "Unable to.."
------------
This does not run:

Dim dt as Date
dt = .Cells (1,1)
If dt Now() Then
MsgBox "Unable to.."
----------
Thanks in advance.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default comparing dates

Thanks, Rob.
I was missing .Value
Regards,

"Rob van Gelder" wrote:

In your 2nd example you're using different names for your variables. dt vs.
date1

Always use Option Explicit.
You can use Date instead of Now which returns just date (not time hh:mm:ss)

Sub test()
Dim dtm As Date

dtm = Cells(1, 1).Value
If dtm <= Date Then
MsgBox "Unable to run"
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Myriam" wrote in message
...
I'm trying to test for a specific date.
If todays date is greater than the date in cell A1
then complete the action, else, show the message "Unable to ..."
but unless I use < the comparison does not work. The code
does not run. Why is this?
The following runs:
-------------
Dim dt as Date
dt = .Cells (1,1)
If date1 < Now() Then
MsgBox "Unable to.."
------------
This does not run:

Dim dt as Date
dt = .Cells (1,1)
If dt Now() Then
MsgBox "Unable to.."
----------
Thanks in advance.







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
Comparing Dates John Excel Discussion (Misc queries) 4 October 5th 09 08:43 PM
Comparing dates Gareth.Evans Excel Worksheet Functions 3 March 25th 09 07:05 PM
Comparing 2 Dates JWeaver Excel Worksheet Functions 3 August 14th 08 09:01 PM
Comparing Dates fubdap Excel Discussion (Misc queries) 3 September 27th 07 03:53 PM
Comparing dates Debbie F Excel Worksheet Functions 7 September 7th 05 11:57 AM


All times are GMT +1. The time now is 08:51 AM.

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

About Us

"It's about Microsoft Excel"