-2

2 つの時刻の時差を計算するプログラムを作成しました。ある程度まで(または適切には少数のセルまで)の時間差を計算します。few cells書き込み後garbage values to the rest of the cells

私を助けてください。以下のコードを参照してください。

Sub Average()
Dim LogIn As String
Dim LogOff As String
Dim Row As Integer
Dim Col As Integer
Dim InTime As Date
Dim OffTime As Date
Row = 1
Col = 2
While (Cells(Row, Col) <> "")
Workbooks("Log-In-Time.xlsm").Activate
InTime = Cells(Row, Col)
Workbooks("Log-Off-Time.xlsm").Activate
OffTime = Cells(Row, Col)
Workbooks("Log-In-Time.xlsm").Activate
Cells(Row, Col + 1) = CDate(OffTime) - CDate(InTime)'<- Without CDate also I have tried but output was same.
Row = Row + 1
Wend
End Sub

私のLog-In-Time.xlsの内容は、

                           OUTPUT
7/11/2013   11:35:41 AM 7:14:15 AM
7/15/2013   11:05:22 AM 10:03:00 AM
7/16/2013   9:58:25 AM  11:11:31 AM
7/17/2013   10:33:20 AM 10:39:25 AM
7/18/2013   11:10:33 AM 6:58:35 AM
7/19/2013   12:18:59 AM 7:18:09 PM <-----Here onwadrs
7/22/2013   11:58:26 AM 0.370185185
7/23/2013   11:27:14 AM 0.418645833
7/24/2013   10:59:36 AM 0.439953704
7/25/2013   11:20:16 AM 0.382650463
7/26/2013   11:09:14 AM 0.373171296

Log-Off-Time.xls の内容は、

7/11/2013   6:49:56 PM
7/15/2013   9:08:22 PM
7/16/2013   9:09:56 PM
7/17/2013   9:12:45 PM
7/18/2013   6:09:08 PM
7/19/2013   7:37:08 PM
7/22/2013   8:51:30 PM
7/23/2013   9:30:05 PM
7/24/2013   9:33:08 PM
7/25/2013   8:31:17 PM
7/26/2013   8:06:36 PM
4

1 に答える 1

0

やっと答えが出た…

以下のコードを追加しただけです。

Dim Diff As Date

Diff = CDate(OffTime) - CDate(InTime)

以下の完全なコードを見つけてください。

Sub Average()
Dim LogIn As String
Dim LogOff As String
Dim Diff As Date
Dim Row As Integer
Dim Col As Integer
Dim InTime As Date
Dim OffTime As Date
Row = 1
Col = 2
While (Cells(Row, Col) <> "")
Workbooks("Log-In-Time.xlsm").Activate
InTime = Cells(Row, Col)
Workbooks("Log-Off-Time.xlsm").Activate
OffTime = Cells(Row, Col)
Workbooks("Log-In-Time.xlsm").Activate
Diff = CDate(OffTime) - CDate(InTime)
Cells(Row, Col + 1) = Diff
Row = Row + 1
Wend
End Sub
于 2013-07-26T15:26:36.230 に答える