Issue at time change (spring forward) in excel vba.

Russel R

New Member
Joined
Jan 4, 2019
Messages
1
Sub Scheduler()
'Decliration of variables and their types.
Dim wb As Workbook
Dim sh1 As Worksheet
Dim schedule_time As Integer
Dim wait_time As String
Dim r_time As Integer

'Saves the workbook.
ActiveWorkbook.Save

'Sets the current workbook and current sheet to be used.
Set wb = ActiveWorkbook
Set sh1 = wb.Sheets("Reports")


r_time = 60 - Minute(Now())
schedule_time = r_time + 10

If schedule_time = 60 Then
Application.OnTime Now() + TimeValue("01:00:00"), "Hourly_Work"
Else
wait_time = "00:" & CStr(schedule_time) & ":00"
Application.OnTime (Now + TimeValue(wait_time)), "Hourly_Work"
End If

End Sub
________________________________________________________________________________________________________________________
Above is the code. The issue is at the text in red. What this does is it schedules the hourly work for the next hour ten minutes after the hour. Problem is when it schedules, it runs into an issue because the hour has already passed in spring forward time change and gives me a debug error for the line in red. As for the reports it skips the 2o'clock hour line and fills in the 3o'clock hour line instead, which is fine but then stops with the error if the code continues to run and fills in the the other hours as they come up wouldn't be a problem.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top