Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing SUMIFS to add time duration always gives 00:00:00
    primarykey
    data
    text
    <pre><code>Sub Add_sumf() Dim i As Integer i = 3 Dim cellDate As Integer cellDate = 0 Dim cellDate1 As Date cellDate1 = TimeValue("00:00:00") Dim total As Integer total = 0 Dim j As Integer j = 2 Dim k As Integer k = 2 Set aa = Workbooks("Book3").Worksheets(1) Set bb = Workbooks("Final_result").Worksheets(1) Do While bb.Cells(1, k).Value &lt;&gt; "" For Each y In bb.Range("A:A") On Error GoTo Label If UCase(bb.Cells(j, "A").Value) &lt;&gt; "" Then cellDate1 = WorksheetFunction.SumIfs(aa.Range("F:F"), aa.Range("B:B"), UCase(bb.Cells(1, k).Value), aa.Range("G:G"), UCase(bb.Cells(j, "A").Value)) bb.Cells(j, k).Value = TimeValue(cellDate1) cellDate1 = TimeValue("00:00:00") bb.Cells(j, k).NumberFormat = "[h]:mm:ss" On Error GoTo Label j = j + 1 Else Exit For End If Next j = 2 k = k + 1 Loop Label: 'MsgBox Err.Description Exit Sub End Sub </code></pre> <p>I am using above code to add time duration based upon value of two other columns but I always get 00:00:00 as result.</p> <p>if i use below code i get the answer but its too slow very slow</p> <pre><code>Sub add_it_time() Dim i As Integer i = 3 Dim cellDate As Integer cellDate = 0 Dim cellDate1 As Date cellDate1 = TimeValue("00:00:00") Dim total As Integer total = 0 Dim j As Integer j = 2 Dim k As Integer k = 2 Set aa = Workbooks("Book3").Worksheets(1) Set bb = Workbooks("Final_result").Worksheets(1) Do While bb.Cells(1, k).Value &lt;&gt; "" 'MsgBox bb.Cells(1, k).Value For Each y In bb.Range("A:A") On Error GoTo Label ' MsgBox UCase(bb.Cells(j, "A").Value) If UCase(bb.Cells(j, "A").Value) &lt;&gt; "" Then For Each x In aa.Range("F:F") On Error Resume Next If UCase(aa.Cells(i, "B").Value) = UCase(bb.Cells(j, "A").Value) Then ' MsgBox aa.Cells(i, "F").Text ' total = total + Int(get_Second(aa.Cells(i, "F").Text)) If UCase(aa.Cells(i, "G").Value) = UCase(bb.Cells(1, k).Value) Then 'MsgBox aa.Cells(i, "F").Text cellDate1 = cellDate1 + TimeValue(aa.Cells(i, "F").Value) End If End If i = i + 1 Next i = 3 On Error GoTo Label bb.Cells(j, k).NumberFormat = "h:mm:ss" bb.Cells(j, k).Value = WorksheetFunction.Text(cellDate1, "[hh]:mm:ss") total = 0 cellDate1 = 0 j = j + 1 Else Exit For End If Next j = 2 k = k + 1 Loop Label: 'MsgBox Err.Description Exit Sub End Sub </code></pre> <p>The source column which contains date is of general formatt I am new to VBA macros</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload