Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
I'm trying to put a loop together that cycles through each worksheet in a workbook and performs an =sum(first cell:last cell) three times for three different years, however the loop doesn't work, it only performs the task for the first worksheet, could anyone please assist?
Thanks
I'm trying to put a loop together that cycles through each worksheet in a workbook and performs an =sum(first cell:last cell) three times for three different years, however the loop doesn't work, it only performs the task for the first worksheet, could anyone please assist?
Thanks
Code:
Sub Totaler()
'Add year totals in cells K14, K27 & K40
Dim i As Long
Application.ScreenUpdating = False
For i = 1 To Worksheets.Count
With Sheets(i)
.Range("K14").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-12]C:R[-1]C)"
.Range("K27").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-12]C:R[-1]C)"
.Range("K40").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-12]C:R[-1]C)"
End With
Next i
Sheets(1).Select
Application.ScreenUpdating = False
End Sub