Calculating the amount of hours with VBA

Teeks2k

New Member
Joined
Aug 1, 2017
Messages
20
Hello,

I am creating a template for another team to track the time it takes to handle a case. This VBA macro is being added to a button for that individual to press to calculate the time.

Here's what I have,

Cell B2 has a starting date & time in this format "3/31/17 3:40 PM", cell E2 has an end date & time "4/12/17 12:15 PM". I am wanting to calculate the amount of hours passed from start to end excluding weekends and holidays
Here is the code I started with:

Code:
Private Sub CommandButton2_Click()
Dim wb As Workbook
Dim wks As Worksheet
Dim wksLR As Long, row As Long

Set wb = ThisWorkbook
Set wks = wb.Sheets("2017 Formulary Box Issue Log")
wksLR = wks.Cells(wks.Rows.Count, 1).End(xlUp).row

    With wks
        For row = 2 To wksLR
        On Error Resume Next
            .Cells(row + 1, 7) = Format(((.Cells(row + 1, 5) - .Cells(row + 1, 2)) * 24), "#.00")
                 Next row
    End With

Set wks = Nothing
Set wb = Nothing
End Sub

This is the type of result I am looking for minus weekends and holidays. I tried to use "worksheetfunction.networkdays" but that only told me how many days had passed excluding weekends and holidays, and did not take into account the time the case was started. I guess I am looking to put these two codes together but not sure how to do it.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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