View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Sum the Variable Range

Try this:
Dim lastrow As Long
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
..Cells(lastrow, "A").FormulaR1C1 _
= "=sum(r2c:r[-1]c)"

Notice, this sums elements in ColumnA, starting in Row2 and continuing down
through the last Row of the ColumnA


Ryan---

--
RyGuy


"Stefi" wrote:

Try something like this:

firstempty = Range("D2").End(xlDown).Row
Range("D" & firstempty).Formula = "=SUM(D2:D" & firstempty - 1 & ")"

Regards,
Stefi

€˛Sheikh Saadi€¯ ezt Ć*rta:

Hi,
I want to sum the values of a column through VBA code. The problem is; I can
sum the value if the Range is static in the column, but if that is a variable
range, which is my case, my code is useless there.
Can anybody help me to sum up the values present in variable range in
columns first empty cell?


Thanks,


sarfraz1

--
Sheikh Saadi