amend VBA code to subtract 1 hour from working hours

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, I use the below VBA code to generate working hours. I need it to subtract 1 hour from the total? Any thoughts?

Code:
Public Sub Worksheet_Change(ByVal Target As Range)


   Dim Cell As Range
   
   ' Calculate working hours if start and finish are both present
   For Each Cell In Target
      If (Cell.Column = [M3].Column Or Cell.Column = [N3].Column) And _
         (IsDate(Cells(Cell.Row, "M")) And IsDate(Cells(Cell.Row, "N"))) Then
         Cells(Cell.Row, "O") = WorkingHours.WorkingHours(Cells(Cell.Row, "M"), Cells(Cell.Row, "N"))
      End If
   Next Cell


End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
What type of value does the WorkingHours function return? If it is just a number just subtract 1 :D

I assume it is more complicated but I have not used that function before. Is that something you made?
 
Upvote 0
Tried that method with no results. it returns a time value - 9:00 This was made for me to calculate working hours between a start and end time. between 8:00 - 5:00 normal work week.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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