LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Totals An Easier Way??

Replace
Range("E5").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E6").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"


BY

For j = 5 to 7
Cells(j, 5).FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
next j

NOTE this also works but involves more typing (therefore is more
error-prone!)
Range("E5").FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E6").FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E7").FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Sue" wrote in message
...
Hi Bernard

Thanks for the quick reply and it worked Ok when I changed the Sheet Name
see below

Sub Macro4 ()
Application.ScreenUpdating = False
Set mysheets = Sheets(Array("Com;In;Av"))
For Each ws In mysheets
ws.Activate
Range("A6:B6").Copy Range("A7") 'note that Copy can specify a target
For j = 3 To 6
Cells(7, j).FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Next j
Next ws
End Sub

However in column E the calc is a division as below
Range("E5").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E6").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"

And I don't know how to fit this into your code?

--
Many Thanks

Sue


"Bernard Liengme" wrote:

Hi Sue,
There is no need to select a cell before you do something to it -- took
me a
while to grasp this concept!
The macro below does what the first 16 lines of your code does. As you
progress, the code saving will increase.

Sub Macro4()
Application.ScreenUpdating = False
Set mysheets = Sheets(Array("com", "in", "av"))
For Each ws In mysheets
ws.Activate
Range("A6:B6").Copy Range("A7") 'note that Copy
can
specify a target
For j = 3 To 6
Cells(7, j).FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Next j
Next ws
End Sub

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Sue" wrote in message
...
Hi All

I have just used the macro recorder and was wondering if there is an
easier
and less complicated way than the code below

Sub Macro4()
Application.ScreenUpdating = False
Sheets("Com;In;Av").Select
Range("A6:B6").Select
Selection.Copy
Range("A7").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C7").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D7").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/d)"
Range("F7").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A9:B9").Select
Selection.Copy
Range("A10").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E10").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F10").Select
ActiveCell.FormulaR1C1 = "=sum"
Range("F10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A11:B11").Select
Selection.Copy
Range("A13").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C13").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D13").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E13").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F13").Select
ActiveCell.FormulaR1C1 = "=sum"
Range("F13").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A15:B15").Select
Selection.Copy
Range("A16").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C16").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D16").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E16").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F16").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A18:B18").Select
Selection.Copy
Range("A19").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C19").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D19").Select
ActiveCell.FormulaR1C1 = "=sum"
Range("D19").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E19").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F19").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E7").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("A21:B21").Select
Selection.Copy
Range("A22").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C22").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D22").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E22").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F22").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A24:B24").Select
Selection.Copy
Range("A25").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C25").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D25").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E25").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F25").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A27:B27").Select
Selection.Copy
Range("A28").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C28").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D28").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E28").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F28").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E29").Select
ActiveWindow.SmallScroll Down:=19
Range("A30:B30").Select
Selection.Copy
Range("A31").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C31").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D31").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E31").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F31").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A33:B33").Select
Selection.Copy
Range("A34").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C34").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D34").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E34").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F34").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A36:B36").Select
Selection.Copy
Range("A37").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C37").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D37").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E37").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F37").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"


Range("A39:B39").Select
Selection.Copy
Range("A40").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C40").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D40").Select
ActiveCell.FormulaR1C1 = "=sum"
Range("D40").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E40").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C/R[-1]C)"
Range("F40").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A42:B42").Select
Selection.Copy
Range("A43").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C43").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D43").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E43").Select
ActiveCell.FormulaR1C1 = "=SUM(R[1]C[-2]/R[1]C[-1])"
Range("E43").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F43").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("A45:B45").Select
Selection.Copy
Range("A46").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C46").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("D46").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("E46").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F46").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("A48:B48").Select
Selection.Copy
Range("A49").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C49").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D49").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E49").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F49").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("A51:B51").Select
Selection.Copy
Range("A52").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C52").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("D52").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("E52").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F52").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("A54:B54").Select
Selection.Copy
Range("A55").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C55").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("D55").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("E55").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F55").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("A57:B57").Select
Selection.Copy
Range("A58").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C58").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("D58").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C+R[-1]C)"
Range("E58").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]/RC[-1])"
Range("F58").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("E59").Select

Range("A7:F7").Select
Selection.Copy

Range("A70").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

Range("A10:F10").Select
Application.CutCopyMode = False
Selection.Copy



 
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 daily totals to weekly totals [email protected] Excel Programming 3 March 28th 08 02:26 PM
Pivot Totals: Group totals different from Grand totals PsyberFox Excel Discussion (Misc queries) 1 February 13th 08 06:16 PM
how to enter totals and sub totals from receipts into excel. mjd23 New Users to Excel 2 January 11th 08 01:54 AM
Find and match totals Genius Req. this should be easier to read James Excel Worksheet Functions 1 October 3rd 05 10:12 PM
Comparing/matching totals in a column to totals in a row Nicole L. Excel Worksheet Functions 3 January 27th 05 10:42 PM


All times are GMT +1. The time now is 06:03 AM.

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

About Us

"It's about Microsoft Excel"