ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sum the Variable Range (https://www.excelbanter.com/excel-programming/425729-sum-variable-range.html)

Sheikh Saadi

Sum the Variable Range
 
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

Stefi

Sum the Variable Range
 
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


ryguy7272

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


Sheikh Saadi

Sum the Variable Range
 
Thanks a lot both of you (Stefi and ryguy)€¦ it helps me a lot€¦

--
Sheikh Saadi


"ryguy7272" wrote:

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


Stefi

Sum the Variable Range
 
You are welcome! Thanks for the feedback!
Stefi

€˛Sheikh Saadi€¯ ezt Ć*rta:

Thanks a lot both of you (Stefi and ryguy)€¦ it helps me a lot€¦

--
Sheikh Saadi


"ryguy7272" wrote:

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



All times are GMT +1. The time now is 03:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com