bdsii
01-07-2010, 07:10 AM
I am uploading a sample file (hopefully) that contains the problem code.
I have created a spreadsheet and supporting code to allow me to type a begin date and an end date and the macro will calculate the number of work hours between the two dates based on "calendar" tab in the spreadsheet.
I have a piece of code that checks to make sure the end date is after the start date for a sanity check for the user.
For some reason, I believe it could be a formatting issue, there are times when I get the error notice that "the End Date must be after the Start Date" incorrectly. Both dates were declared as Strings .
I get that error when I used the following data:
Start = 2/4/2010 and End = 12/31/2010
but not when I enter 1/4/2010 and 12/31/2010
I also get the error when Start = 9/1/2009 and End is 10/1/2009
The code to perform this check is:
If enddate < begindate Then
Sheets("Calculations").Select
MsgBox " End Date should be BEFORE Start Date !"
Exit Sub
End If
I used code to format the dates so that if you enter 9/1/2009 or 09/01/2009 it would convert to 9/1/2009 and work with the searches. That snippet of code is:
enddate = Range("D5").Value
enddate = Format(enddate, "Short Date")
I hope to maintain the code I have in the spreadsheet, I just need advice on the problem and how to correct it inside the code I have.
help...anyone ? :dunno
thanks!
I have created a spreadsheet and supporting code to allow me to type a begin date and an end date and the macro will calculate the number of work hours between the two dates based on "calendar" tab in the spreadsheet.
I have a piece of code that checks to make sure the end date is after the start date for a sanity check for the user.
For some reason, I believe it could be a formatting issue, there are times when I get the error notice that "the End Date must be after the Start Date" incorrectly. Both dates were declared as Strings .
I get that error when I used the following data:
Start = 2/4/2010 and End = 12/31/2010
but not when I enter 1/4/2010 and 12/31/2010
I also get the error when Start = 9/1/2009 and End is 10/1/2009
The code to perform this check is:
If enddate < begindate Then
Sheets("Calculations").Select
MsgBox " End Date should be BEFORE Start Date !"
Exit Sub
End If
I used code to format the dates so that if you enter 9/1/2009 or 09/01/2009 it would convert to 9/1/2009 and work with the searches. That snippet of code is:
enddate = Range("D5").Value
enddate = Format(enddate, "Short Date")
I hope to maintain the code I have in the spreadsheet, I just need advice on the problem and how to correct it inside the code I have.
help...anyone ? :dunno
thanks!