Forum Discussion
Excel
Jun 26, 2022Iron Contributor
Loop in Sum with the help of VBA code
Hello Everyone, When we run the loop multiple time, its adding up and filling the next cells down. what function to be given to to get the sum value which sticks to single cell ? Please help...
- Jun 26, 2022
Sub AutomateSum() Dim lastrow As String Dim ws As Worksheet For Each ws In Worksheets Worksheets(ws.Name).Select Range("E2").Select Selection.End(xlDown).Select lastrow = ActiveCell.Row ActiveCell.Offset(1, 1).Select ActiveCell.Value = "=sum(F2:F" & lastrow & ")" Next ws End SubYou can try the attached file with these lines of code.
OliverScheurich
Jun 26, 2022Gold Contributor
Sub AutomateSum()
Dim lastrow As String
Dim ws As Worksheet
For Each ws In Worksheets
Worksheets(ws.Name).Select
Range("E2").Select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row
ActiveCell.Offset(1, 1).Select
ActiveCell.Value = "=sum(F2:F" & lastrow & ")"
Next ws
End SubYou can try the attached file with these lines of code.
Excel
Jun 26, 2022Iron Contributor
It work...
Thank you so much sir...
Thank you so much sir...