Macro_Nerd99
Board Regular
- Joined
- Nov 13, 2021
- Messages
- 61
- Office Version
- 365
What's a more effective way to write this code so I don't have to insert text into cells and then delete it?
Also, how would I display the total hours worked in 40:00:00 format, instead of a 40.0 decimal format?
Any other advice/feedback is appreciated.
Also, how would I display the total hours worked in 40:00:00 format, instead of a 40.0 decimal format?
Any other advice/feedback is appreciated.
VBA Code:
Public Sub Calculate_Hours()
Dim StartTime as date
dim EndTime as date
dim i as integer
dim lr as long
dim fr as long
dim total_hours as long
With thisworkbook.activesheet.autofilter.Range
fr = Range("B" & .offset(1,0).specialcells(xlcelltypevisible)(1).row).row
lr = cells(Rows.Count,"C").end(xlUp).row
end with
for i = fr to lr
StartTime = ws.range("B" & i).value
EndTime = ws.Range("C".value
ws.range("H" & i).value = datediff("n", starttime, EndTime)/60
Next i
Total_hours = application.worksheetfunction.sum(Range("H" & fr & ":H" & lr))
Filter_Form.hours_tb.text= Total_hours
Range("H" & fr & ":h" & lr).clearcontents
End Sub