Hi everyone, Im learning VBA and I have this code
</pre>
And the result is </pre>
Time Date Result</pre>
</pre>00:21.6 10/1/2012 1:43 FALSE 00:21.6
01:47.7 10/1/2012 2:13 FALSE 01:47.7
00:56.7 10/1/2012 2:49 FALSE 00:56.7
00:54.9 10/1/2012 3:43
00:11.8 10/1/2012 3:43
02:10.9 10/1/2012 3:46 FALSE 3:17.6(ie.,00:54.9+..+2:10.9)
01:05.4 10/1/2012 3:58 FALSE 01:05.4
00:55.8 10/1/2012 4:53
04:41.8 10/1/2012 4:52
00:26.3 10/1/2012 4:58
00:04.2 10/1/2012 4:58
00:15.3 10/1/2012 4:59
00:06.4 10/1/2012 4:57
00:10.7 10/1/2012 4:56
00:04.4 10/1/2012 4:56
00:04.2 10/1/2012 4:57
00:29.2 10/1/2012 4:57
00:34.5 10/1/2012 4:56
01:22.4 10/1/2012 4:55
00:08.1 10/1/2012 4:55 FALSE 9:23.3(i.e.,00:55.8+...+:08.1)
03:20.9 10/1/2012 4:51 FALSE 03:20.9
00:56.3 10/1/2012 5:42 FALSE 00:56.3
That works fine, but in the inverse procedure that i need to implement. In my spreadsheet the counting starts in the first non blank cell and goes throghout the blank cells until the next non blank cell is reached, and then input the sum in the last blank cell (sum A cells from the first non blank until the last blank cell and then start again from the next non blank cell).
Thanks
00:21.6 10/1/2012 1:43 FALSE 00:21.6
01:47.7 10/1/2012 2:13 FALSE 01:47.7
00:56.7 10/1/2012 2:49 FALSE
00:54.9 10/1/2012 3:43
00:11.8 10/1/2012 3:43 2:34(00:56.7 +00:54.9+00:11.8)
02:10.9 10/1/2012 3:46 FALSE 02:10.9
01:05.4 10/1/2012 3:58 FALSE
00:55.8 10/1/2012 4:53
04:41.8 10/1/2012 4:52
00:26.3 10/1/2012 4:58
00:04.2 10/1/2012 4:58
00:15.3 10/1/2012 4:59
00:06.4 10/1/2012 4:57
00:10.7 10/1/2012 4:56
00:04.4 10/1/2012 4:56
00:04.2 10/1/2012 4:57
00:29.2 10/1/2012 4:57
00:34.5 10/1/2012 4:56
01:22.4 10/1/2012 4:55 (01:05.400:55.8+04:41.8+...+01:22.4)
00:08.1 10/1/2012 4:55 FALSE 00:08.1
Code:
[/FONT]Sub SmartRunningTotals()</pre> Dim rng As Range
Dim cell As Range
Dim lastRow As Long
Dim totalTime As Double
' I'm assuming your time column is in column A
lastRow = Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
Set rng = Range("A2:A" & lastRow)
For Each cell In rng
totalTime = totalTime + cell.Value
If cell.Offset(, 2).Value <> "" Then
cell.Offset(, 3).Value = totalTime
' reset total after we write it to column D
totalTime = 0
End If
Next
End Sub
</pre>
And the result is </pre>
Time Date Result</pre>
</pre>00:21.6 10/1/2012 1:43 FALSE 00:21.6
01:47.7 10/1/2012 2:13 FALSE 01:47.7
00:56.7 10/1/2012 2:49 FALSE 00:56.7
00:54.9 10/1/2012 3:43
00:11.8 10/1/2012 3:43
02:10.9 10/1/2012 3:46 FALSE 3:17.6(ie.,00:54.9+..+2:10.9)
01:05.4 10/1/2012 3:58 FALSE 01:05.4
00:55.8 10/1/2012 4:53
04:41.8 10/1/2012 4:52
00:26.3 10/1/2012 4:58
00:04.2 10/1/2012 4:58
00:15.3 10/1/2012 4:59
00:06.4 10/1/2012 4:57
00:10.7 10/1/2012 4:56
00:04.4 10/1/2012 4:56
00:04.2 10/1/2012 4:57
00:29.2 10/1/2012 4:57
00:34.5 10/1/2012 4:56
01:22.4 10/1/2012 4:55
00:08.1 10/1/2012 4:55 FALSE 9:23.3(i.e.,00:55.8+...+:08.1)
03:20.9 10/1/2012 4:51 FALSE 03:20.9
00:56.3 10/1/2012 5:42 FALSE 00:56.3
That works fine, but in the inverse procedure that i need to implement. In my spreadsheet the counting starts in the first non blank cell and goes throghout the blank cells until the next non blank cell is reached, and then input the sum in the last blank cell (sum A cells from the first non blank until the last blank cell and then start again from the next non blank cell).
Thanks
00:21.6 10/1/2012 1:43 FALSE 00:21.6
01:47.7 10/1/2012 2:13 FALSE 01:47.7
00:56.7 10/1/2012 2:49 FALSE
00:54.9 10/1/2012 3:43
00:11.8 10/1/2012 3:43 2:34(00:56.7 +00:54.9+00:11.8)
02:10.9 10/1/2012 3:46 FALSE 02:10.9
01:05.4 10/1/2012 3:58 FALSE
00:55.8 10/1/2012 4:53
04:41.8 10/1/2012 4:52
00:26.3 10/1/2012 4:58
00:04.2 10/1/2012 4:58
00:15.3 10/1/2012 4:59
00:06.4 10/1/2012 4:57
00:10.7 10/1/2012 4:56
00:04.4 10/1/2012 4:56
00:04.2 10/1/2012 4:57
00:29.2 10/1/2012 4:57
00:34.5 10/1/2012 4:56
01:22.4 10/1/2012 4:55 (01:05.400:55.8+04:41.8+...+01:22.4)
00:08.1 10/1/2012 4:55 FALSE 00:08.1