PDA

View Full Version : Solved: Date Stuff



tonyrosen
11-16-2005, 12:41 PM
Which I don't think is anything other than I'm not versed in this stuff well enough ...

Let's say you have two dates (StartDate and StopDate)

'====================================
StartDate = Range("A3") 'assuming it's already a date
StopDate = Range("A4") 'assuming it's already a date
StopYear = Year(StartDate) + 1
AfterThisDate = "12/31/" & StopYear
'====================================

I need to check to see if the StopDate is less than the AfterThisDate ...

Basically:
If StopDate < AfterThisDate Then
'Throw an error
End If

However, it's not calculating unless the dates are equal ... Am I missing something?

Ken Puls
11-16-2005, 12:50 PM
Hi there,

I declared the variables for you, but it seemed to work as is.

Dates used:
Range("A3") = 1/31/2005
Range("A4") = 5/13/2005

Sub CheckDate()
Dim startdate As Date
Dim stopdate As Date
Dim stopyear As Long
Dim afterthisdate As Date

startdate = Range("A3") 'assuming it's already a date
stopdate = Range("A4") 'assuming it's already a date
stopyear = Year(startdate) + 1
afterthisdate = "12/31/" & stopyear
If stopdate < afterthisdate Then
'Throw an error
MsgBox "error"
End If
End Sub

Let me know if it still isn't doing what you need.

tonyrosen
11-16-2005, 01:20 PM
Ah ... it was the declaring the variables part ... I had declared them as strings. The minute I changed that to Date, it worked perfectly.

Thanks.

Ken Puls
11-16-2005, 02:50 PM
Gald to help, Tony!

:)