Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Adding totals to columns where number of rows varies

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)"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Adding totals to columns where number of rows varies

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)"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Adding totals to columns where number of rows varies

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" wrote
in message ...
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)"



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Adding totals to columns where number of rows varies

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)"

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Adding totals to columns where number of rows varies

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" wrote
in message ...
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
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
Adding totals from different columns Eskercat Excel Worksheet Functions 1 April 13th 10 03:06 PM
Adding totals in columns Tanya Excel Worksheet Functions 2 February 9th 10 06:56 PM
Counting columns, adding totals #2 Dennis Allen Excel Programming 2 July 5th 04 04:59 AM
Counting columns, adding totals #2 Dennis Allen Excel Programming 1 July 2nd 04 08:13 PM
Counting columns, adding totals Dennis Allen Excel Programming 7 July 1st 04 07:34 PM


All times are GMT +1. The time now is 01:19 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"