Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 12:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"