Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Correct Macro for Totals

Hi All

I am trying to use this macro shown below to produce a total line at the
bottom of each sheet I am using.

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
ActiveCell.SpecialCells(xlLastCell).Select
Range("E10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range("E10").Select
Selection.AutoFill Destination:=Range("A10:E10"), Type:=xlFillDefault
Range("A10:E10").Select
End Sub

The problem is the the number of rows varies from each sheet, so the totals
will be in the wrong place for most of the sheets.
Is there any way that the total per column can be offset so they are say 2
rows below the bottom number on each sheet?

Many thanks

franklin

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default Correct Macro for Totals

For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

For i = 1 To 5

nRow = sh.Cells(sh.Rows.Count, i).Row
sh.Cells(nRow + 2, i).FormulaR1C1 = "=SUM(R1C:R[-1]C)"
Next i
Next sh


--
__________________________________
HTH

Bob

"franklin via OfficeKB.com" <u47278@uwe wrote in message
news:8dde310471a2b@uwe...
Hi All

I am trying to use this macro shown below to produce a total line at the
bottom of each sheet I am using.

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
ActiveCell.SpecialCells(xlLastCell).Select
Range("E10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range("E10").Select
Selection.AutoFill Destination:=Range("A10:E10"), Type:=xlFillDefault
Range("A10:E10").Select
End Sub

The problem is the the number of rows varies from each sheet, so the
totals
will be in the wrong place for most of the sheets.
Is there any way that the total per column can be offset so they are say 2
rows below the bottom number on each sheet?

Many thanks

franklin

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Correct Macro for Totals

I think Bob left off an ".end(xlup)" in his code.

This version uses the data in column E to determine the last row to add and it
doesn't leave an empty row between the last detail row and the total row:

Option Explicit
Sub testme()

Dim sh As Object
Dim i As Long
Dim nRow As Long

For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
nRow = sh.Cells(sh.Rows.Count, "E").End(xlUp).Row
For i = 1 To 5
sh.Cells(nRow + 1, i).FormulaR1C1 = "=SUM(R1C:R[-1]C)"
Next i
Next sh

End Sub



Bob Phillips wrote:

For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

For i = 1 To 5

nRow = sh.Cells(sh.Rows.Count, i).Row
sh.Cells(nRow + 2, i).FormulaR1C1 = "=SUM(R1C:R[-1]C)"
Next i
Next sh

--
__________________________________
HTH

Bob

"franklin via OfficeKB.com" <u47278@uwe wrote in message
news:8dde310471a2b@uwe...
Hi All

I am trying to use this macro shown below to produce a total line at the
bottom of each sheet I am using.

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
ActiveCell.SpecialCells(xlLastCell).Select
Range("E10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range("E10").Select
Selection.AutoFill Destination:=Range("A10:E10"), Type:=xlFillDefault
Range("A10:E10").Select
End Sub

The problem is the the number of rows varies from each sheet, so the
totals
will be in the wrong place for most of the sheets.
Is there any way that the total per column can be offset so they are say 2
rows below the bottom number on each sheet?

Many thanks

franklin

--
Message posted via http://www.officekb.com


--

Dave Peterson
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
Correct syntax for IF, Then in a macro Ken[_2_] Excel Worksheet Functions 5 June 21st 08 06:19 PM
How do you correct inaccurate sumif totals? Analyst Excel Worksheet Functions 2 August 15th 07 11:59 PM
Correct Macro so that if the person is not in the source document jeannie v Excel Worksheet Functions 6 June 23rd 07 02:00 PM
my pivot tables are correct but my totals and GT don't show muzikman360 Excel Discussion (Misc queries) 2 February 2nd 07 06:52 PM
Please correct my macro famdamly Excel Discussion (Misc queries) 5 March 5th 06 08:45 PM


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