View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JW[_2_] JW[_2_] is offline
external usenet poster
 
Posts: 638
Default VBA Time comparison not correct

On May 19, 4:10*pm, wright wrote:
Another note to mention, is that by entering the value manually (i.e. typing
19:00 into cell B1141) and rerunning the vba script it seems to correct the
error. So this is probably something funky to do with autofill.


Search for the text instead of the value

Sub mmm()
For n = 1 To 1440
If Cells(n, 1).Text = Cells(3, 3).Text Then
Cells(n, 2) = 1
End If
Next n
End Sub

But, there is no need to go through all the looping. Try something
like this
Sub anotherWay()
Range("A1:A1440").Find(What:="19:00", After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Offset(0, 1) = 1
End Sub