Results 1 to 20 of 20

Add VBA to extract hours 2 times (in and out)

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-02-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    235

    Add VBA to extract hours 2 times (in and out)

    Hello,

    I am trying add to this code I started building and stuck on adding VBA to extract hours from 2 times (columns). The problem is I need to get these hrs, but then -.50. So for example if the hours extracted from 2 times is 7hs I want the result to be 6.5hrs (hence the -.50).

    Here is the attachment and what is highlighted in yellow is where I would like the hours calculate (Columns C:I).

    Any help would be MUCH APPRECIATED!

    Here is the code.
    Sub Add_Breaks()
    
    Dim ws As Worksheet
    Dim Cell As Range
    Application.ScreenUpdating = False
    
    'For Each ws In ThisWorkbook.Sheets
    'Find 6.5 hrs mark
    
        For Each Cell In ActiveSheet.Range("F:F,L:L")
            If Not IsEmpty(Cell.Offset(, -1).Value) And IsDate(Cell.Offset(, -1).Text) Then
                Cell.Value = Cell.Offset(, -2).Value + TimeSerial(5, 59, 0)
                Cell.NumberFormat = "hh:mm"
            End If
        Next Cell
        
        Columns("F:F").Select
        Selection.NumberFormat = "[$-409]h:mm AM/PM;@"
        Columns("L:L").Select
        Selection.NumberFormat = "[$-409]h:mm AM/PM;@"
        Cells.Select
        Selection.Replace What:="blank", Replacement:="Min Break", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        
            Columns("C:C").Select
        Selection.NumberFormat = "[$-409]h:mm AM/PM;@"
        Columns("I:I").Select
        Selection.NumberFormat = "[$-409]h:mm AM/PM;@"
        Cells.Select
        Selection.Replace What:="Meal", Replacement:="Sched Hrs", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            
        'Highlight Blue
    
    With Range("F:F, L:L")
        .Font.Color = vbBlue
         .Font.Bold = True
    
    End With
        
        'Colums Autofit
        
        Columns("F:F").EntireColumn.AutoFit
        Columns("L:L").EntireColumn.AutoFit
        
        'Fix page break
        
        ActiveWindow.View = xlPageBreakPreview
        ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
        ActiveSheet.PageSetup.PrintArea = "$A$1:$L$54"
        ActiveWindow.View = xlNormalView
        
        
        Range("A2").Select
        
        Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files
    Last edited by g1terra; 01-23-2020 at 11:20 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Finding Ship Times based on Hours of Shipper and Hours of Receiver
    By kmsagent in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-01-2019, 02:31 AM
  2. [SOLVED] Formula needed to extract number of hours worked, dependent on shift times
    By heidithecat in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-21-2018, 04:30 AM
  3. Replies: 3
    Last Post: 04-23-2016, 01:42 AM
  4. Replies: 2
    Last Post: 03-02-2013, 10:57 AM
  5. [SOLVED] Formula to work out hours between 2 dates and times.. MINUS Out Of Hours
    By chris.m in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-30-2012, 08:11 AM
  6. [SOLVED] Calculation of hourly rate times hours times 1.5
    By Newbusinessbod in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-06-2005, 12:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1