Consulting

Results 1 to 5 of 5

Thread: vba subtract time from date

  1. #1

    vba subtract time from date

    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

  2. #2
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    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

  3. #3
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    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

  4. #4
    Problem Solved! Thanks

  5. #5
    VBAX Expert mperrah's Avatar
    Joined
    Mar 2005
    Posts
    744
    Location
    Glad to help,
    be sure to use thread tools and mark as solved
    -mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •