PDA

View Full Version : date comparison on two ranges



crmpicco
12-19-2005, 03:42 AM
'... if the cells are not empty then change the number format
'... to the date format DD MMM YY
If Range(sRange).Text <> "" Then
Range(sRange).NumberFormat = "dd mmm yy"
End If
If Range(sTempRange).Text <> "" Then
Range(sTempRange).NumberFormat = "dd mmm yy"
End If


Is there a way to check if the text/value inside sTempRange is not earlier than the text/value inside sRange??

For e.g. I have a problem in my sheet as sRange = 29-Dec-05 and sTempRange = 31-Mar-05.

Can i do a check or something for this?

Thanks.

Picco
http://vbaexpress.com/forum/images/smilies/banghead.gif

crmpicco
12-19-2005, 03:46 AM
Dim dateFirst As System.DateTime
Dim dateSecond As System.DateTime
dateFirst = txtFirstDate.Text.Trim()
dateSecond = args.Value
If dateSecond < dateFirst Then
args.IsValid = False
valSecondDate.ErrorMessage = "Second Date must be equal to or later than First Date!"
Exit Sub
End If


I found this code for what i think is VB.NET?

Can this be used

Bob Phillips
12-19-2005, 04:36 AM
Not tested


Dim dateFirst As System.DateTime
Dim dateSecond As Date
dateFirst = CDate(Range(sRange).Text)
dateSecond = CDate(Range(sTempRange).Text)
If dateSecond < dateFirst Then
MsgBox "Second Date must be equal to or later than First Date!"
Exit Sub
End If