Autosum function
Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim tmpSub As Double, tmpTotal As Double
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
tmpSub = Range("A1").Value
For i = 2 To iLastRow + 1
If Cells(i, "A") < "" Then
tmpSub = tmpSub + Cells(i, "A").Value
Else
Cells(i, "A").Value = tmpSub
tmpTotal = tmpTotal + tmpSub
tmpSub = 0
End If
Next i
Cells(i, "A").Value = tmpTotal
End Sub
--
HTH
Bob Phillips
(remove xxx from email address if mailing direct)
"Frankie" wrote in message
...
I have a list of numbers with all in same column. When clicking normal
autosum function, Excel determines the sum range for me, including
subtotals
& grandtotals.
How can this happen with same effect in VBA language so that I need not
define the sum ranges (variable).
E.g.
1
2
3
click autosum : =sum(1:3)
4
5
click autosum : =sum(4:5)
click autosum : =sum(above subtotals)
|