-
You can skip the Autofill step
[VBA]Sub Formula2()
Dim nMonth As Long, nProd As Long
With Range("B4")
nMonth = Range(.Offset(0, 0), .End(xlToRight)).Columns.Count
nProd = Range(.Offset(0, 0), .End(xlDown)).Rows.Count
End With
Range("A" & nProd + 4).Value = "Total"
Range("A3").Offset(0, nMonth + 1).Value = "Total"
Range("B" & nProd + 4).Resize(1, nMonth).Formula = _
"=SUM(B4:B" & nProd + 3 & ")"
Cells(4, nMonth + 2).Resize(nProd).Formula = _
"=SUM(B4:" & Split(Cells(4, 1 + nMonth).Address(, 0), "$")(0) & "4)"
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules