PC Review


Reply
Thread Tools Rate Thread

Adding totals to columns where number of rows varies

 
 
=?Utf-8?B?Um9kIGZyb20gQ29ycmVjdGlvbnM=?=
Guest
Posts: n/a
 
      22nd Feb 2007
I have a report that is exported into Excel from another application, and I
am attempting to write a macro to make some formatting changes. The number
of rows of data changes depending upon the report parameters.

Data appears in columns from A to H, and I want totals at the bottom of
columns G and H only.

The following code that I got off of this site does almost what I need,
except that I end up with totals in more than just the two columns that I
want. How do I limit the range so that I get totals only in G and H?

Set rng = ActiveSheet.UsedRange
Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Um9kIGZyb20gQ29ycmVjdGlvbnM=?=
Guest
Posts: n/a
 
      22nd Feb 2007
Perfect! Thanks!

"JLGWhiz" wrote:

> Sub totColGH()
> lr = Cells(Rows.Count, 7).End(xlUp).Row
> Set rng = ActiveSheet.Range(Cells(1, 7), Cells(lr, 8))
> Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
> rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
> End Sub
>
>
> "Rod from Corrections" wrote:
>
> > I have a report that is exported into Excel from another application, and I
> > am attempting to write a macro to make some formatting changes. The number
> > of rows of data changes depending upon the report parameters.
> >
> > Data appears in columns from A to H, and I want totals at the bottom of
> > columns G and H only.
> >
> > The following code that I got off of this site does almost what I need,
> > except that I end up with totals in more than just the two columns that I
> > want. How do I limit the range so that I get totals only in G and H?
> >
> > Set rng = ActiveSheet.UsedRange
> > Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
> > rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
> >

 
Reply With Quote
 
Trevor Shuttleworth
Guest
Posts: n/a
 
      22nd Feb 2007
Try:

Set rng = ActiveSheet.UsedRange
Set rng = rng.Rows(rng.Rows.Count).Offset(2, 6).Resize(1, 2).Cells
rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"

Regards

Trevor


"Rod from Corrections" <(E-Mail Removed)> wrote
in message news2C3AE2C-1960-4E2F-9A79-(E-Mail Removed)...
>I have a report that is exported into Excel from another application, and I
> am attempting to write a macro to make some formatting changes. The
> number
> of rows of data changes depending upon the report parameters.
>
> Data appears in columns from A to H, and I want totals at the bottom of
> columns G and H only.
>
> The following code that I got off of this site does almost what I need,
> except that I end up with totals in more than just the two columns that I
> want. How do I limit the range so that I get totals only in G and H?
>
> Set rng = ActiveSheet.UsedRange
> Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
> rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
>



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      22nd Feb 2007
Sub totColGH()
lr = Cells(Rows.Count, 7).End(xlUp).Row
Set rng = ActiveSheet.Range(Cells(1, 7), Cells(lr, 8))
Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
End Sub


"Rod from Corrections" wrote:

> I have a report that is exported into Excel from another application, and I
> am attempting to write a macro to make some formatting changes. The number
> of rows of data changes depending upon the report parameters.
>
> Data appears in columns from A to H, and I want totals at the bottom of
> columns G and H only.
>
> The following code that I got off of this site does almost what I need,
> except that I end up with totals in more than just the two columns that I
> want. How do I limit the range so that I get totals only in G and H?
>
> Set rng = ActiveSheet.UsedRange
> Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
> rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
>

 
Reply With Quote
 
=?Utf-8?B?Um9kIGZyb20gQ29ycmVjdGlvbnM=?=
Guest
Posts: n/a
 
      22nd Feb 2007
That worked, too! Thanks, Trevor.

"Trevor Shuttleworth" wrote:

> Try:
>
> Set rng = ActiveSheet.UsedRange
> Set rng = rng.Rows(rng.Rows.Count).Offset(2, 6).Resize(1, 2).Cells
> rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
>
> Regards
>
> Trevor
>
>
> "Rod from Corrections" <(E-Mail Removed)> wrote
> in message news2C3AE2C-1960-4E2F-9A79-(E-Mail Removed)...
> >I have a report that is exported into Excel from another application, and I
> > am attempting to write a macro to make some formatting changes. The
> > number
> > of rows of data changes depending upon the report parameters.
> >
> > Data appears in columns from A to H, and I want totals at the bottom of
> > columns G and H only.
> >
> > The following code that I got off of this site does almost what I need,
> > except that I end up with totals in more than just the two columns that I
> > want. How do I limit the range so that I get totals only in G and H?
> >
> > Set rng = ActiveSheet.UsedRange
> > Set rng = rng.Rows(rng.Rows.Count).Offset(2, 0).Cells
> > rng.FormulaR1C1 = "=Sum(R[-1]C:R1C)"
> >

>
>
>

 
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
Adding totals from different columns Eskercat Microsoft Excel Worksheet Functions 1 13th Apr 2010 03:06 PM
Adding totals in columns Tanya Microsoft Excel Worksheet Functions 2 9th Feb 2010 06:56 PM
Sub Totals with multiple rows and columns Himansu Microsoft Excel Programming 0 1st Nov 2005 08:34 PM
Counting columns, adding totals #2 Dennis Allen Microsoft Excel New Users 8 10th Jul 2004 01:57 AM
Counting columns, adding totals Dennis Allen Microsoft Excel New Users 5 2nd Jul 2004 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 AM.