Sub 巨集1()
T1 = Now
Range("C2:C3").NumberFormatLocal = "yyyy/mm/dd hh:mm:ss;@"
Range("C2") = T1
TimeDadd = InputBox("請輸入要增加的時間(日)", , 0)
If TimeDadd = "" Then TimeDadd = 0
TimeHadd = InputBox("請輸入要增加的時間(時)", , 0)
If TimeHadd = "" Then TimeHadd = 0
TimeHadd = TimeHadd / 24
TimeMadd = InputBox("請輸入要增加的時間(分)", , 0)
If TimeMadd = "" Then TimeMadd = 0
TimeMadd = TimeMadd / 24 / 60
TimeSadd = InputBox("請輸入要增加的時間(秒)", , 0)
If TimeSadd = "" Then TimeSadd = 0
TimeSadd = TimeSadd / 24 / 60 / 60
Range("C3") = T1 + TimeDadd + TimeHadd + TimeMadd + TimeSadd
Range("C3").Select
End Sub
小改一下將輸入資料放C4
Sub 巨集1()
T1 = Now
InputData = ""
Range("C4").ClearContents
Range("C2:C3").NumberFormatLocal = "yyyy/mm/dd hh:mm:ss;@"
Range("C2") = T1
TimeDadd = InputBox("請輸入要增加的時間(日)", , 0)
If TimeDadd = "" Then TimeDadd = 0
If TimeDadd > 0 Then InputData = InputData & TimeDadd & " 日 "
TimeHadd = InputBox("請輸入要增加的時間(時)", , 0)
If TimeHadd = "" Then TimeHadd = 0
If TimeHadd > 0 Then InputData = InputData & TimeHadd & " 時 "
TimeHadd = TimeHadd / 24
TimeMadd = InputBox("請輸入要增加的時間(分)", , 0)
If TimeMadd = "" Then TimeMadd = 0
If TimeMadd > 0 Then InputData = InputData & TimeMadd & " 分 "
TimeMadd = TimeMadd / 24 / 60
TimeSadd = InputBox("請輸入要增加的時間(秒)", , 0)
If TimeSadd = "" Then TimeSadd = 0
If TimeSadd > 0 Then InputData = InputData & TimeSadd & " 秒 "
TimeSadd = TimeSadd / 24 / 60 / 60
Range("C3") = T1 + TimeDadd + TimeHadd + TimeMadd + TimeSadd
If Range("C2").Value = Range("C3").Value Then
Range("C4") = "輸入資料均為 0 "
Else
Range("C4") = "輸入資料為 " & InputData
End If
Range("C3").Select
End Sub
真的太感謝了這符合我的需求
我這邊還有個問題想問
在我輸入完"日時分秒"後
我想另外在儲存格上顯示我剛剛輸入的"日時分秒"
能否再麻煩你 謝謝
Range("C4") = TimeDadd & TimeHadd & TimeMadd & TimeSadd
https://docs.microsoft.com/zh-tw/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/concatenation-operators
來杯拿鐵
加上後顯示如下
我想應該是因為有時分制計算的原因
能否請協助修正 謝謝
Sub 按鈕1_Click()
T1 = Now
Range("B2:C2").NumberFormatLocal = "yyyy/mm/dd hh:mm;@"
Range("B2") = T1
TimeHadd = InputBox("輸入(時)", , 0)
Range("D2") = TimeHadd & TimeMadd
If TimeHadd = "" Then TimeHadd = 0
TimeHadd = TimeHadd / 24
TimeMadd = InputBox("輸入(分)", , 0)
If TimeMadd = "" Then TimeMadd = 0
TimeMadd = TimeMadd / 24 / 60
Range("D2") = TimeHadd & TimeMadd
Range("C2") = T1 + TimeHadd + TimeMadd
Range("C2").Select
End Sub