Loop through workbook and calculate sum in each worksheet

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
34
Hello,

I'm trying to have my code figure out how many worksheets there are and to loop through each one to calculate and place the sum of column F in the first blank row in column F in each worksheet. My code is only partly working. Please Help!

Sub WorksheetLoop()



Dim lastRowInColA As Integer
Dim totPointsRow As Integer
Dim columnSum As Double
Dim LastRowNum As Long
Dim WS_Count As Integer

' Set WS_Count equal to the number of worksheets in the active
' workbook.

WS_Count = ActiveWorkbook.Worksheets.Count


' Begin the loop through all sheets
For i = 1 To WS_Count


With ActiveWorkbook.Worksheets(i).Range("F" & Rows.Count).End(xlUp).Select


lastRowInColA = Selection.Row
totPointsRow = lastRowInColA + 1
Range("E" & totPointsRow) = "Total:"
Range("F" & totPointsRow) = Application.WorksheetFunction.Sum(Columns("F:F"))



End With

Next i

End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
How about
Code:
Sub I3atnumb3rs()
   Dim Ws As Worksheet

   For Each Ws In Worksheets
      With Ws.Range("F" & Rows.Count).End(xlUp).Offset(1)
         .Offset(, -1).Value = "Total:"
         .FormulaR1C1 = "=sum(r1c:r[-1]c)"
         .Value = .Value
      End With
   Next Ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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