View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
wright wright is offline
external usenet poster
 
Posts: 7
Default VBA Time comparison not correct

I have a worksheet with a column of time values (column A). I entered the
first 3 manually

00:00
00:01
00:02
and then autofilled down to 23:59


I have another cell(c3) formatted the same as column A which I placed
another time value into 19:00.

In VBA I am comparing the time in C3 and with each of the values in column A
and if the times are the same I am placing a 1 in column B next to the same
time.

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

This is an oversimplification of a much more complex project but it
demonstrates the error exactly. The problem is that there are certain values
that do not seem to match even though they should. For example when I run
this with the value of 19:00 in C3 column b has no values even though B1141
should = 1.