0
votes

I currently have a workbook with multiple worksheets, including a master worksheet. My current VBA provides a sum total for specified columns in the master worksheet and this works perfectly well.

However, I would like to edit the VBA so I can have sum values for columns on different worksheets too. I have attached the code for reference below, if anyone can suggest how I might edit it in order to include more than one worksheet would be greatly appreciated.

`Sub AutoSum()
Sheets("MASTER ACCOUNT REVENUE").Select
Range("D4").Select
Range("F4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
Dim cel1 As String, cel2 As String
cel1 = ActiveCell.Offset(-2, 0).End(xlUp).Address
cel2 = ActiveCell.Offset(-1).Address
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"
End Sub` 
1

1 Answers

0
votes

I have three worksheets with a value in "A1." This subroutine shows the sum of all of those values in the cell "A2" on the worksheet in which the code resides:

Sub sum()

Range("a2") = Worksheets(2).Range("a1") + Worksheets(3).Range("a1") + Range("a1")

End Sub