View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_14_] Bob Phillips[_14_] is offline
external usenet poster
 
Posts: 216
Default 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)