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
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