VB Code to Sum Between Blank Cells

khanhngo102

New Member
Joined
Sep 9, 2011
Messages
2
Hello I have a worksheet which has values in in some cells and blanks in the other. I want to be able to sum between cells starting from top down rather than bottoms up.

Here is a code but it sums from bottom up but I want from top down since the parent is top and child below

Dim LR As Long, a As Long, MyTotD As Double, MyTotE As Double
Application.ScreenUpdating = False
With ActiveSheet
MyTotD = 0: MyTotE = 0
LR = .Cells(Rows.Count, 4).End(xlUp).Row
For a = 2 To LR + 1 Step 1
If Cells(a, 4) <> "" Then
MyTotD = MyTotD + Cells(a, 4)
MyTotE = MyTotE + Cells(a, 5)
Else
With Cells(a, 4)
.Value = MyTotD
.Font.Bold = True
.NumberFormat = "#,##0.00000"
End With
MyTotD = 0
With Cells(a, 5)
.Value = MyTotE
.Font.Bold = True
.NumberFormat = "#,##0.00000"
End With
MyTotE = 0
End If
Next a
End With
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top