Hi,
I have the following code which compares a date in a session of Excel to see if it falls into a specific date-range.
The date I am testing it on is "17/01/06", which is in a cell formatted to be a date in the format DD/MM/YYYY.
The code:
Do Until Excel.ActiveCell.Offset(0, -30).Value = ""
If FormatDateTime(Excel.ActiveCell.Value, vbShortDate) <> "" Then
If Excel.ActiveCell.Value > 31 / 12 / 2006 Then
If Excel.ActiveCell.Value < "01/02/2006" Then
'Add To ReportFormatDateTime6
ActiveCell.Value = ActiveCell.Value + 1
Excel.ActiveCell.Offset(1, 0).Select
Else
Excel.ActiveCell.Offset(1, 0).Select
End If
End If
End If
Loop
I have broken the if statement into three parts to see where it is going wrong. The first two parts work fine - going down to the next parts ok, however the final part doesn't work properly:
If Excel.ActiveCell.Value < "01/02/2006" Then...
Excel doesn't realise that the date (17/01/2006) is less than "01/02/2006".
What am I doing wrong??
I have the following code which compares a date in a session of Excel to see if it falls into a specific date-range.
The date I am testing it on is "17/01/06", which is in a cell formatted to be a date in the format DD/MM/YYYY.
The code:
Do Until Excel.ActiveCell.Offset(0, -30).Value = ""
If FormatDateTime(Excel.ActiveCell.Value, vbShortDate) <> "" Then
If Excel.ActiveCell.Value > 31 / 12 / 2006 Then
If Excel.ActiveCell.Value < "01/02/2006" Then
'Add To ReportFormatDateTime6
ActiveCell.Value = ActiveCell.Value + 1
Excel.ActiveCell.Offset(1, 0).Select
Else
Excel.ActiveCell.Offset(1, 0).Select
End If
End If
End If
Loop
I have broken the if statement into three parts to see where it is going wrong. The first two parts work fine - going down to the next parts ok, however the final part doesn't work properly:
If Excel.ActiveCell.Value < "01/02/2006" Then...
Excel doesn't realise that the date (17/01/2006) is less than "01/02/2006".
What am I doing wrong??