Dim I As Integer '(短整數)資料型態'Public i As interger => 出現使用者型態尚未定義, 正確: Integer
Sub Ex()
Dim xTime As Date
If Time >= #8:45:00 AM# And Time <= #1:30:00 PM# Then
With Sheets("RTD").Cells(I + 3, "T").Resize(, 6)
.Offset(-2).Value = .Offset(-2).Value '上一列:將公式回數值
'T欄公式=IF(ISERROR(MATCH(U2,P:P,0)),"",MATCH(U2,P:P,0))
.Range("A1") = "=MATCH(RC[1],R3C[-19]:R70000C[-19],1)+2"
'X欄公式=IF(W2="","",IF(W2>54,-1,IF(W2<6,1,"")))
.Range("E1") = "=SUM(INDIRECT(""B""&R[-1]C[-4]+1):INDIRECT(""B""&RC[-4]))"
'Y欄公式=IF(ISERROR(INDIRECT("R"&T2)),Y1,INDIRECT("R"&T2))
.Range("F1") = "=SUM(INDIRECT(""C""&R[-1]C[-5]+1):INDIRECT(""C""&RC[-5]))"
'W欄公式=IF(ISERROR(INDIRECT("O"&T2)),"",INDIRECT("O"&T2))
.Range("C1") = "=RC[-2]-R[-1]C[-2]"
'X欄公式=IF(W2="","",IF(W2>54,-1,IF(W2<6,1,"")))
'.Range("E1") = "=IF(RC[-1]="""","""",IF(RC[-1]>54,-1,IF(RC[-1]<6,1,"""")))"
'Y欄公式=IF(ISERROR(INDIRECT("R"&T2)),Y1,INDIRECT("R"&T2))
'.Range("F1") = "=IF(ISERROR(INDIRECT(""R""&RC[-5])),R[-1]C,INDIRECT(""R""&RC[-5]))"
'.Resize(, 6) = .Resize(, 6).Value '將公式回數值
End With
I = I + 1
xTime = Time + #12:01:00 AM#
If xTime <= #1:45:00 PM# Then Application.OnTime xTime, "EX"
ElseIf Time < #8:45:00 AM# Then
Application.OnTime #8:45:00 AM#, "EX"
Else
MsgBox "時間已過"
End If
End Sub
Sub test()
I = TimeValue("08:45:00") '起
Do While I <= TimeValue("13:45:00") '終
If Format(I, "ss") = "57" Then '秒數為57
Application.OnTime Date + I, "工作表1.當57秒時要執行的程序"
End If
If Format(I, "ss") = "01" Then '秒數為01
Application.OnTime Date + I, "工作表1.當01秒時要執行的程序"
End If