ユーザーが2つの別々のコンボボックスcboStartDate、cboStartTimeを介して特定の日付と時刻を入力する必要があるユーザーフォームがあります。また、テキスト フィールド txtDuration に期間を入力する必要があります。
保存すると、開始日時がフォーマットされたセル [DD/MM/YYYY HH:MM AM/PM] に保存されます。終了日時は期間フィールドから計算され、同じフォーマットで別のセルに保存されます。このようなもの:
+-------------------------------------+-----------------------+ | | 開始時間 | 終了時間 | +-------------------------------------+-----------------------+ | | 2012 年 2 月 4 日午前 11:30:00 | 2012 年 2 月 4 日 14:00:00 | +-------------------------------------+-----------------------+
ただし、ユーザーフォームを実行した後、開始時刻は保存されず、終了時刻は計算されません。このようなもの:
+-------------------------------------+-----------------------+ | | 開始時間 | 終了時間 | +-------------------------------------+-----------------------+ | | 2012 年 2 月 4 日 12:00:00 午前 | 2012 年 2 月 4 日 12:00:00 午前 | +-------------------------------------+-----------------------+
以下は私のVBAコードの一部です:
Dim iRow As Long
Dim ws As Worksheet
Dim startDate As Date
Dim unFmtStartDuration() As String
Dim startDuration As Double
Dim minTest As Integer
Dim endDate As Date
Dim endDuration As Double
Set ws = Worksheets("EVENTS")
'Search for the last row in the worksheet
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'Date manipulation and set start and end timings
unFmtStartDuration() = Split(cboStartTime.Text, ":")
startDuration = unFmtStartDuration(0)
If unFmtStartDuration(1) = "00" Then
minTest = 0
Else
minTest = unFmtStartDuration(1)
If minTest = 30 Then
startDuration = startDuration + 0.5
End If
End If
startDate = DateValue(DateAdd("h", startDuration, cboDate.Text & " 12:00AM"))
ws.Cells(iRow, 4).Value = startDate
endDuration = txtDuration.Value
endDate = DateValue(DateAdd("h", endDuration, startDate))
ws.Cells(iRow, 5).Value = endDate
では、この部分を整理するにはどうすればよいでしょうか。ここで何か助けていただければ幸いです。ありがとう。
PSここにスクリーンショットを投稿したいのですが、ここでの私の評判は低すぎます. ごめん。