LOOP with non blank cell

pedrojoin

New Member
Joined
Apr 5, 2013
Messages
5
Hi everyone, Im learning VBA and I have this code
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
 

James Snyder

Well-known Member
Joined
Jan 11, 2013
Messages
618
You need to get your code between the tags. It is very difficult to read as is.
 

Forum statistics

Threads
1,082,114
Messages
5,363,244
Members
400,722
Latest member
DrewPop24

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top