Loop in Sum with the help of VBA code

Super Contributor

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... 


Here is a attached file..

2 Replies
best response confirmed by Zain123 (Super Contributor)


Sub AutomateSum()
    Dim lastrow As String
    Dim ws As Worksheet
    For Each ws In Worksheets
    lastrow = ActiveCell.Row
    ActiveCell.Offset(1, 1).Select
    ActiveCell.Value = "=sum(F2:F" & lastrow & ")"
    Next ws

End Sub

You can try the attached file with these lines of code.



It work...

Thank you so much sir...