PC Review


Reply
Thread Tools Rate Thread

Add Sum to the columns at the last row

 
 
vivi
Guest
Posts: n/a
 
      17th Jul 2009
Hi there, I am using this code here but it doesn't give me the result I
desire as I have a 36 months starting from Column V and data starts at row 7.
The problem is that the starting point is always the same, but my end point
varies depending the number of entries. I would like to add a formula to the
end of each month.

The code I am using is:

Sub Marco()

Dim lastrow2 As Range

ActiveWorkbook.Names.Add Name:="lastrow4", _
RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)

Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
Offset(1, 0)

lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"

End Sub

Instead of calculating the column itself, it calculates from the start point
to the last cell that has a number

Can you help please?

Thanks a lot

Viv
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      17th Jul 2009
Sub Marco()

Dim lastrow2 As Range

ActiveWorkbook.Names.Add Name:="lastrow4", _
RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)

Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
Offset(1, 0)

lastrow2.Formula = "=SUM(C1:C" & lastrow2.Row - 1 & ")"

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"vivi" wrote:

> Hi there, I am using this code here but it doesn't give me the result I
> desire as I have a 36 months starting from Column V and data starts at row 7.
> The problem is that the starting point is always the same, but my end point
> varies depending the number of entries. I would like to add a formula to the
> end of each month.
>
> The code I am using is:
>
> Sub Marco()
>
> Dim lastrow2 As Range
>
> ActiveWorkbook.Names.Add Name:="lastrow4", _
> RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
>
> Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> Offset(1, 0)
>
> lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"
>
> End Sub
>
> Instead of calculating the column itself, it calculates from the start point
> to the last cell that has a number
>
> Can you help please?
>
> Thanks a lot
>
> Viv

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Jul 2009
This sums c7:v? whatever the last row in col C is. Does it below last row in
col C

Sub sumcolc()
lr = Cells(Rows.Count, "c").End(xlUp).Row
Cells(lr + 1, "c").Formula = "=sum(c7:v" & lr & ")"
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"vivi" <(E-Mail Removed)> wrote in message
news:4D420A74-9682-4A69-8E30-(E-Mail Removed)...
> Hi there, I am using this code here but it doesn't give me the result I
> desire as I have a 36 months starting from Column V and data starts at row
> 7.
> The problem is that the starting point is always the same, but my end
> point
> varies depending the number of entries. I would like to add a formula to
> the
> end of each month.
>
> The code I am using is:
>
> Sub Marco()
>
> Dim lastrow2 As Range
>
> ActiveWorkbook.Names.Add Name:="lastrow4", _
> RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
>
> Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> Offset(1, 0)
>
> lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"
>
> End Sub
>
> Instead of calculating the column itself, it calculates from the start
> point
> to the last cell that has a number
>
> Can you help please?
>
> Thanks a lot
>
> Viv


 
Reply With Quote
 
vivi
Guest
Posts: n/a
 
      17th Jul 2009
Hi There

Thanks for this, this work perfectly

At the moment i just fix to column c as I am just playing around with it

I have actually 250 columns to insert this formula

Do you have a suggestion to loop this instead of writing 250 lines of code
for each column?

I thought of using similar code to set the column as a variant and loop it
by adding 1 each time. But i keep having an error and refuse to let me go
further !!!

Thanks a lot

"Jacob Skaria" wrote:

> Sub Marco()
>
> Dim lastrow2 As Range
>
> ActiveWorkbook.Names.Add Name:="lastrow4", _
> RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
>
> Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> Offset(1, 0)
>
> lastrow2.Formula = "=SUM(C1:C" & lastrow2.Row - 1 & ")"
>
> End Sub
>
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "vivi" wrote:
>
> > Hi there, I am using this code here but it doesn't give me the result I
> > desire as I have a 36 months starting from Column V and data starts at row 7.
> > The problem is that the starting point is always the same, but my end point
> > varies depending the number of entries. I would like to add a formula to the
> > end of each month.
> >
> > The code I am using is:
> >
> > Sub Marco()
> >
> > Dim lastrow2 As Range
> >
> > ActiveWorkbook.Names.Add Name:="lastrow4", _
> > RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
> >
> > Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> > Offset(1, 0)
> >
> > lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"
> >
> > End Sub
> >
> > Instead of calculating the column itself, it calculates from the start point
> > to the last cell that has a number
> >
> > Can you help please?
> >
> > Thanks a lot
> >
> > Viv

 
Reply With Quote
 
vivi
Guest
Posts: n/a
 
      17th Jul 2009
Forgot to give you what I've written, it didn't give me an error but it takes
a long time and froze excel, but it should be short as only a small test ...I
had to stop it by pressing esc

Sub Marco()

Dim lastrow2 As Range

Do Until qcol = 20

qcol = 8

ActiveWorkbook.Names.Add Name:="lastrow4", _
RefersToR1C1:=ActiveSheet.Cells(Rows.Count, [qcol]).End(xlUp)

Set lastrow2 = ActiveSheet.Cells(Rows.Count, [qcol]).End(xlUp). _
Offset(1, 0)

lastrow2.Formula = "=SUM(C1:C" & lastrow2.Row - 1 & ")"

qcol = qcol + 1

Loop

End Sub

"Jacob Skaria" wrote:

> Sub Marco()
>
> Dim lastrow2 As Range
>
> ActiveWorkbook.Names.Add Name:="lastrow4", _
> RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
>
> Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> Offset(1, 0)
>
> lastrow2.Formula = "=SUM(C1:C" & lastrow2.Row - 1 & ")"
>
> End Sub
>
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "vivi" wrote:
>
> > Hi there, I am using this code here but it doesn't give me the result I
> > desire as I have a 36 months starting from Column V and data starts at row 7.
> > The problem is that the starting point is always the same, but my end point
> > varies depending the number of entries. I would like to add a formula to the
> > end of each month.
> >
> > The code I am using is:
> >
> > Sub Marco()
> >
> > Dim lastrow2 As Range
> >
> > ActiveWorkbook.Names.Add Name:="lastrow4", _
> > RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
> >
> > Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
> > Offset(1, 0)
> >
> > lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"
> >
> > End Sub
> >
> > Instead of calculating the column itself, it calculates from the start point
> > to the last cell that has a number
> >
> > Can you help please?
> >
> > Thanks a lot
> >
> > Viv

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      17th Jul 2009
This will use col C as the longest row and put the sum formula for c:H.
Modify to suit
If c is not the longest row, use another.

Sub sumcolc()
lr = Cells(Rows.Count, "c").End(xlUp).Row
Cells(lr + 1, "c").Resize(, 6).Formula = _
"=sum(c1:c" & lr & ")"

End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This sums c7:v? whatever the last row in col C is. Does it below last row
> in col C
>
> Sub sumcolc()
> lr = Cells(Rows.Count, "c").End(xlUp).Row
> Cells(lr + 1, "c").Formula = "=sum(c7:v" & lr & ")"
> End Sub
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "vivi" <(E-Mail Removed)> wrote in message
> news:4D420A74-9682-4A69-8E30-(E-Mail Removed)...
>> Hi there, I am using this code here but it doesn't give me the result I
>> desire as I have a 36 months starting from Column V and data starts at
>> row 7.
>> The problem is that the starting point is always the same, but my end
>> point
>> varies depending the number of entries. I would like to add a formula to
>> the
>> end of each month.
>>
>> The code I am using is:
>>
>> Sub Marco()
>>
>> Dim lastrow2 As Range
>>
>> ActiveWorkbook.Names.Add Name:="lastrow4", _
>> RefersToR1C1:=ActiveSheet.Cells(Rows.Count, "C").End(xlUp)
>>
>> Set lastrow2 = ActiveSheet.Cells(Rows.Count, "C").End(xlUp). _
>> Offset(1, 0)
>>
>> lastrow2.FormulaR1C1 = "=SUM(R7C10:lastrow4)"
>>
>> End Sub
>>
>> Instead of calculating the column itself, it calculates from the start
>> point
>> to the last cell that has a number
>>
>> Can you help please?
>>
>> Thanks a lot
>>
>> Viv

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Columns to Rows and insert into another table based on valuesin columns Gurvinder Microsoft Access Form Coding 7 25th Nov 2008 10:03 PM
Convert Columns to Rows and insert into another table based on valuesin columns Gurvinder Microsoft Access Queries 0 24th Nov 2008 09:00 PM
Combine multiple columns into two long columns, Repeating rows in first column anasab@gmail.com Microsoft Excel Misc 2 31st Jul 2006 09:45 PM
Parent Columns and Child Columns don't have type-matching columns microsoft news Microsoft ADO .NET 1 21st Sep 2004 10:08 AM
Xcel or Access sort columns of names so that I remove the intersect between 2 columns from one of the columns? William.R.Reisen Microsoft Access External Data 2 20th Dec 2003 02:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:44 AM.