PDA

View Full Version : vba subtract time from date



gecko0735
05-08-2015, 04:41 AM
I have a workbook with 7 tabs named Monday - Sunday. I use the following to open the tab by the date. What I need is for the date to be 5 hours before the actual date, so it won't change tabs til 5am instead of midnight.

Sub auto_open()
Sheets(Format(Date, ("dddd"))).Select
End Sub

mperrah
05-08-2015, 08:30 AM
try this


Sub auto_open()
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name = Format(Date, ("dddd")) And _
Hour(Now) >= TimeSerial(5, 0, 0) Then
Sheets(Format(Date, ("dddd"))).Select
End If
Next
End Sub
hope this helps
-mark

mperrah
05-08-2015, 09:15 AM
Actually this works:


Sub auto_open()
Dim ws As Worksheet
IF Hour(Now) >= Hour("5:00 am") Then
Sheets(Format(Date, ("dddd"))).Select
End If

End Sub
hope this helps
-mark

gecko0735
05-08-2015, 12:10 PM
Problem Solved! Thanks

mperrah
05-08-2015, 12:32 PM
Glad to help,
be sure to use thread tools and mark as solved
-mark