Calculation of units 1/10 sec and 1/100 sec
It's difficult to calculate a time
When by 1/10 sec or 1/100 sec.
When you input a time value "02:02.9" into a cell,
Excel change automatically the cell's format into "mm:ss.0So".
(In case "02:02.23", the cell's format is changed into "mm:ss.00")
So you can input the time as you will.I
If you change the cell's format "mmss.0" into "normal",
you know that "02:02.9" is equal to "0.0014...".
See also the article:Date And Time about a serial value of date.
『Date And Time
』
After you input two time value into cells, input "=A1-A2" into A3 cell,
so you can get the difference of "02:02.9" and "02:02.5".
(1/100 sec is same way. See B column.)
The next is doing the same thing by VBA.
You need a technique to change"02:02.9" into "0.0014...".
You can use Timevalue Function to change Time by unit of sec.
TimeValue("00:02:02")
This doesn't work by unit of 1/10 sec or 1/100 sec.
TimeValue("02:02.9")
The above is 2 hour 2 min 9 sec.(not 2min 2sec 9/10 sec)
So you can use Timevalue Function for sec unit calculation,
and add the part of 1/10 sec or 1/100 sec by another method.
Then,
TimeValue("00:" & LEFT("02:02.9",5))
The above can convert 2min 2sec to dicimal value.
Next is
1/10 sec=1/24/60/60/10
0.9 sec=9/10 sec=9/24/60/60/10 therefore,
Right("02:02.9", 1) / 24 / 60 / 60 / 10
The above returns dicimal value of 0.9 sec.
Here is the code of the procedure.
Sub macro180103a()
Dim MyTime As String |
Result:
You can apply "macro180103"
to subtract a time values : MyTime1 - MyTime2 by unit of 1/10 sec.
Here is the code.
Sub macro180103b()
Dim MyTime1 As String, MyTime2 As String |
Result:
In addition, you can reuse macro180103b
to make a Function that subtract a time value by unit of 1/10 sec.
Here is the code.
Sub macro180103c()
Cells(1, 1) = TimeCul10("02:02.9", "02:02.5") TimeCul10 = CDbl(TimeValue
("00:" & Left(MyTime1, 5)) _ End Function |
Result of macro180103c:
And then, I made a Function
that subtracts timevalues by unit of 1/100 sec.
Check differences between the the code for 1/10 sec and the code for 1/100 sec.
Sub macro180103d()
Cells(1, 1) = TimeCul100("02:02.23", "02:02.11")
TimeCul100 = CDbl(TimeValue("00:" & Left(MyTime1, 5)) _ End Function |
Result of macro180103d:
If you feel difficult to calculate timevalues by VBA,
you can use a worksheet as easier way.
Input timevalues into cells and calcuate in the cells,
then use the result value by VBA.
| 固定リンク
この記事へのコメントは終了しました。

コメント