VBA Time comparison not correct
This worked for my example but unfortunately creates a new issue with my
actual code.
I am actually (and one of the reasons for the loop) entering 2 times and
want to put a 1 next to all times = the first time and <= the last time.
Dim n As Integer
For n = 1 To 1440
'check if column 1 value is later than H1
If Cells(n, 1) = Cells(1, 8) Then
'check if column 1 value is before I1
If Cells(n, 1) <= Cells(1, 9) Then
Cells(n, 2) = 1
End If
End If
Next n
Now with comparing the text values:
Dim n As Integer
For n = 1 To 1440
'check if column 1 value is later than H1
If Cells(n, 1).Text = Cells(1, 8).Text Then
'check if column 1 value is before I1
If Cells(n, 1).Text <= Cells(1, 9).Text Then
Cells(n, 2) = 1
End If
End If
Next n
and using h1 = 15:00 and I1=23:59
I get 1:00 to 1:59 and 15:00 to 23:59 marked.
(note: I am also doing other calculations in this formula which require the
double if statements and the Cells(r,c) formats)
|