Thursday 26 September 2013

Excel Macros - add totals to every sheet

Watch on YouTube


This macro will add totals after last record in every sheet 

Sub Test()
Dim ws As Worksheet
    For Each ws In Sheets

        ws.Activate
        Dim lastRowWithData As Long
        lastRowWithData = Range("A" & Rows.Count).End(xlUp).Row + 1
        Range("F" & lastRowWithData).FormulaR1C1 = "=Sum(R2C:R[-1]C)"
        Range("G" & lastRowWithData).FormulaR1C1 = "=Sum(R2C:R[-1]C)"
        Range("H" & lastRowWithData).FormulaR1C1 = "=Sum(R2C:R[-1]C)"
        Range("I" & lastRowWithData).FormulaR1C1 = "=Sum(R2C:R[-1]C)"
    Next ws
End Sub

No comments:

Post a Comment