This method should only run during the defined period and then start again from the beginning on the following day. Does anyone have an idea why the method does not start by itself the next day? I have defined that it should start again at 7:50 a.m.
If Time > TimeValue("18:00:00") Or Time < TimeValue("07:49:00") Then
Application.Wait "07:50:00"
Else
Edit: Here is the complete code but without variable declaration. The aim of the macro is to take a value once every hour and copy it into the defined cell.
If Time > TimeValue("18:00:00") Or Time < TimeValue("07:49:00") Then
Application.Wait "07:50:00"
Else
If MyTime >= Format(Time, "hh:00:00") And MyTime < Format(Time, "hh:59:59") Then
MyTime = Format(Time, "hh:00:00")
End If
Set rngData = Tabelle5.Range("A1:L283")
ReDim arr(1 To rngData.Rows.Count, 1 To rngData.Columns.Count)
arr = rngData.Value
With Tabelle5.Range("A1:L1")
Set MyColumn = .Find(MyTime, LookIn:=xlValues)
On Error Resume Next
End With
For i = LBound(arr, 1) To UBound(arr, 1)
If arr(i, 1) = MyDate Then
x = i
Exit For
End If
Next i
Set MyAddress = Cells(x, MyColumn.Column)
On Error Resume Next
Tabelle1.Range("C11").Copy
Tabelle5.Range(MyAddress.Address).PasteSpecial xlPasteValues
Tabelle4.Range("B2") = Now
Application.OnTime Now() + TimeValue("01:00:00"), "DatenabrufCAL23"
End If
Thanks for your help!