以下代码继续添加23:59HRS到日期,我需要每天运行代码4 - 5次,它将添加,直到它更改初始日期。我只是想在没有添加它的情况下直到那天结束。
Dim x As Integer
Dim test1 As Date
Dim schdWS, compWS As Worksheet
Const H23M59 As Double = 1 - 60 / 86400
Set schdWS = Sheet1
Set compWS = Sheet11
lastrow = schdWS.Cells(Rows.Count, 8).End(xlUp).Row
For x = 20 To lastrow
If IsDate(schdWS.Cells(x, 3).Value) Then
Cells(x, 3).Value = CDate(Int(Cells(x, 3).Value + H23M59))
End If
Next x
End sub
答案 0 :(得分:0)
使用以下
替换循环内的If
If IsDate(schdWS.Cells(x, 3).Value) Then
'Get rid of hours, min and secs
TheDay = Int(schdWS.Cells(x, 3).Value)
TheEndOfDay = TheDay + H23M59
'I write the result in col4 for clarity. Replace according to your needs.
schdWS.Cells(x, 4).Value = Format(TheEndOfDay, "YYYY/MM/DD HH:MM:SS")
End If