Moving from one column to the next

segran

Active Member
Joined
Aug 20, 2004
Messages
335
Hi,

I have a workbook with 51 sheets, labelled as week 2 to week 52.
Each sheet captures data for a week in the same cells.

I want to automatically sum a few ranges in the respective sheets into Sheet1.
The sum for the respective rows for Week2 will be in column A, whilst for week3 in column B, and so on.

I recorded a macro for Week2 and Week3:

Sub Macro4()
'
' Macro4 Macro
'

'
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Sheet1").Select ' sheet1 is the sheet i want data summed to
ActiveCell.FormulaR1C1 = "=SUM('Week 2'!R[8]C[24]:R[8]C[28])"
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:A9"), Type:=xlFillDefault
Range("A1:A9").Select

Range("B1").Select
ActiveCell.FormulaR1C1 = "=SUM('Week 3'!R[8]C[23]:R[8]C[27])"
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B9"), Type:=xlFillDefault
Range("B1:B9").Select
End Sub

How do I do this automatically for all sheet?

Thanking you in advance for your help.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try:

Code:
Sub Test()
    Dim c As Long
    For c = 1 To 51
        Cells(1, c).Resize(9).FormulaR1C1 = "=SUM('Week " & c + 1 & "'!R[8]C[" & 25 - c & "]:R[8]C[" & 29 - c & "])"
    Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top