DudethatsSweet
New Member
- Joined
- Jul 5, 2018
- Messages
- 3
Hi!
Im trying to get this formula to work. It calculates the total hours from start time to end time and converts it to numbers instead of time.
When executed it gives a runtime 1004 error. When i copy the formula by hand it will work just fine. Can someone please help me out?
Below the VBA code. Thanks in advance!
Sub CalculateTotalHours()
Dim tbl As ListObject
Dim sFormula As String
Set tbl = Sheets("Data").ListObjects("DataTable")
sFormula = "=IF([@[End Time]]<[@[Start Time]];(([@[End Time]]-[@[Start Time]]+24)*24);([@[End Time]]-[@[Start Time]])*24)"
tbl.ListColumns(").DataBodyRange.Cells(1).Formula = sFormula
End Sub
Im trying to get this formula to work. It calculates the total hours from start time to end time and converts it to numbers instead of time.
When executed it gives a runtime 1004 error. When i copy the formula by hand it will work just fine. Can someone please help me out?
Below the VBA code. Thanks in advance!
Sub CalculateTotalHours()
Dim tbl As ListObject
Dim sFormula As String
Set tbl = Sheets("Data").ListObjects("DataTable")
sFormula = "=IF([@[End Time]]<[@[Start Time]];(([@[End Time]]-[@[Start Time]]+24)*24);([@[End Time]]-[@[Start Time]])*24)"
tbl.ListColumns(").DataBodyRange.Cells(1).Formula = sFormula
End Sub