ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time Comparison (https://www.excelbanter.com/excel-programming/375116-time-comparison.html)

Charles in Iraq

Time Comparison
 
Greetings.

I've written a form that allows users to take a timestamp in
HH:mm:ss format and then insert it, in correct order, into a list
of other timestamps.

In order to insert the timestamp in its correct order, I loop
over the list until I find a value greater than the value of my
timestamp. I then insert a new row and place my timestamp
in the row I just created.

My problem is that I can't get my time comparison to work
properly. Here is how I attempt to do the comparison:

For i = 2 To LastRow
If CDate(EventTimer.EventClock.Value) CDate(Sheet2.Cells(i, 3).Value)
Then
Sheet2.Rows(i).Insert
Sheet2.Cells(i, 1) = i - 1
Sheet2.Cells(i, 3) = EventTimer.InputTime

'Increment places on the remaining rows.
For j = (i + 1) To (LastRow + 1)
Sheet2.Cells(j, 1) = j - 1
Next j
EventTimer.PlaceList.RowSource = EventTimer.PlaceList.RowSource
Exit Sub
End If
Next i

My row is always inserted at the top of the list, even though I know
the value entered into the EventClock field of the EventTimer form
is greater than the first item on the list.

Somehow the If statement where I compare the times just isn't
working.

What's wrong with my comparison? Do I need to bracket the times
with the # characters, as I've done before programming Acess?
Do I need to somehow better massage the contents of the EventClock
field or the Cells that I am comparing this against?

Respectfully,

Charles

Bob Phillips

Time Comparison
 
How about this

i = Application.Match(EventTimer.EventClock.Value, Sheet2.Range("C2:C" &
lastrow), 1) + 1
Sheet2.Rows(i).Insert
Sheet2.Cells(i, 1) = i - 1
Sheet2.Cells(i, 3) = EventTimer.InputTime


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Charles in Iraq" wrote in message
...
Greetings.

I've written a form that allows users to take a timestamp in
HH:mm:ss format and then insert it, in correct order, into a list
of other timestamps.

In order to insert the timestamp in its correct order, I loop
over the list until I find a value greater than the value of my
timestamp. I then insert a new row and place my timestamp
in the row I just created.

My problem is that I can't get my time comparison to work
properly. Here is how I attempt to do the comparison:

For i = 2 To LastRow
If CDate(EventTimer.EventClock.Value) CDate(Sheet2.Cells(i,

3).Value)
Then
Sheet2.Rows(i).Insert
Sheet2.Cells(i, 1) = i - 1
Sheet2.Cells(i, 3) = EventTimer.InputTime

'Increment places on the remaining rows.
For j = (i + 1) To (LastRow + 1)
Sheet2.Cells(j, 1) = j - 1
Next j
EventTimer.PlaceList.RowSource = EventTimer.PlaceList.RowSource
Exit Sub
End If
Next i

My row is always inserted at the top of the list, even though I know
the value entered into the EventClock field of the EventTimer form
is greater than the first item on the list.

Somehow the If statement where I compare the times just isn't
working.

What's wrong with my comparison? Do I need to bracket the times
with the # characters, as I've done before programming Acess?
Do I need to somehow better massage the contents of the EventClock
field or the Cells that I am comparing this against?

Respectfully,

Charles





All times are GMT +1. The time now is 06:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com