I can't find you problem from your postings, biut I can explain why you are
getting different results
1)
We now know that you times are starting at zero. You don't have any date
information in the time when it displays 12/31/1899 12:01:45 AM. This
really means you went back almost one day. Jan 1, 1900 minus 1 plus 1 hour
and 45 seconds.
A time (not a date) is entered into excel "01:45:33" defaults to day one Jan
1, 1900.
2)
This is important in debugging the problem. You need to find out why you
have text instead of a numbe
----------------------------------------------------------------------------------
I also noticed that 12/31/1899 12:01:45 AM seems to be stored in the cell as
text. If i change the number format of the cell it makes no difference at all.
----------------------------------------------------------------------------------
3)
Lets say I clicked the button at 21:35:24 on the 7 august (so just now). The
cell shows 7/8/2009 9:35:24 PM which seems fine but if I convert it to
general format it comes up as 40032.89958. Is this right. Maybe that's the
number of days since 1/1/1900.
You are correct!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
will get you hours
89958 * 24 = 21.58992
or use a formula
hour(40032.89958) = 21
21 hours
to get minutes
..58992 * 60 = 35.3952
35 minute
or use formula
minute(40032.89958) = 35
To get seconds
..3952 * 60 = 23.712
23 seconds
or use formula
second(40032.89958) = 23
4) Now lets look at your code
If Time2.Value - LastLap > 1.2 * Range("d" & riderCell.Row) Or Time2.Value
- LastLap < 0.8 * Range("d" & riderCell.Row) Then
You have to make sure that Time2.lap and LastLap either both contains DATE
and TIME or both have only Time
If you have Aug 2 9:00 AM - Aug 1 10:00 PM you will get 11 hours which will
equal 11/24. Actually this is equivalent to Jan 1 , 1900 at 11:00 AM, but
the date isn't important.
If you have just 9:00 AM - 10:00 PM you will get -11/24. A minus time which
excel will the is Dec 31, 1899. The date doesn't matter.
You may getr incrrect information if you combine dates and time together.
If my start timne is
Aug 1, 2009 at 9:00 AM and my end time is just a time 10:00 AM then this
will get weird results
Jan 1, 1900 10:00 AM - Aug 1, 2009 9:00 AM
5) if you are mixing dates and time here are two tricks
If you want to add 10 hours to todays date
Int(now) get you midnight of any date
you can add a time and date
Int(now) + 10/24 get you 10:00 AM
or you can use a function
Int(now) + TimeSerial(10, 0, 0)
or
Int(now) + TimeValue("10:00 AM")
6) going the opposite way
Remove the date from the time
now mod 1
NDBC said:
I also noticed that 12/31/1899 12:01:45 AM seems to be stored in the cell as
text. If i change the number format of the cell it makes no difference at all.
NDBC said:
Thanks Joel. When I use
Time1.Value = Now - Sheets("Timing Sheet").Range("B6")
I get a time of 12/31/1899 12:01:45 AM stored in the cell at an elapsed time
of 24:01:45. Excel then can not work with numbers before 1900. I am not even
sure how it can come with this number. The time stored in b6 is
6/08/2009 9:18:56 PM (as in 6 August, I'm an aussie). Any ideas what's
happening.
Joel said:
First You don't need the workshet function to perform this
Time1.Value = WorksheetFunction.Text(Now - Sheets("Timing
Sheet").Range("B6"), "[hh]:mm:ss")
use
Time1.Value = Format(Now - Sheets("Timing Sheet").Range("B6"), "[hh]:mm:ss")
This line is producting TEXT which is the problem.
Replace with this
Time1.Value = Now - Sheets("Timing Sheet").Range("B6")
Now is producing time from Jan 1, 1900 which will be larger the 24 hours (or
larger than 1)
To get at time less than 24 hours use mod function
Time1.Value = (Now mod 1) - Sheets("Timing Sheet").Range("B6")
Excel uses a number (not text) to store time and just changes the formaing
when displaying the time one the screen.
Jan 1, 1900 is day 1 and each day incremetns by 1. An hour is equivalent to
1/24 and a minute is equivalent to 1/(24 * 60) and a second 1/(24 * 60 * 60).
:
I am inputing an elapsed time with the following code and it is working fine,
Time1.Value = WorksheetFunction.Text(Now - Sheets("Timing
Sheet").Range("B6"), "[hh]:mm:ss")
The problem occurs when I go to put the next elapsed time in the adjacent
cell. I have an if statement that checks if the lap time is within 20% of the
teams average.
If Time2.Value - LastLap > 1.2 * Range("d" & riderCell.Row) Or Time2.Value
- LastLap < 0.8 * Range("d" & riderCell.Row) Then
When I go through debugger the lastlap time is working fine and is general
format, so when over 24hrs is something like 1.00347222. The time2.value
shows as "24:10:23" which is the actual elapsed time since the start of the
race to when they finish the lap. For some reason the two don't want to work
together.
I tried timevalue(time2.value) but this doesn't work if the elapsed time is
24hrs.
Thanks