Macro to sum cells from other sheets into one

Closed
maz - 24 Nov 2010 à 17:04
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 25 Nov 2010 à 04:25
Hello, I want to sum cells from other sheets which have the same format, into one sheet using a macro (ie instead of the manual excel function =sum(sheet1,A1+Sheet2,A1 etc).
Any help is greatly appreciated

Thanks



1 response

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
25 Nov 2010 à 04:25
I prsume you want sheet1!a1+sheet2!a1+sheet3!a1 etc

insert a new sheet and call it "master"

try this macro (the total pops up and also copied in A1 of sheet "master"


Sub test()
Dim j As Long, k As Long, tot As Double
j = Worksheets.Count
tot = 0
For k = 1 To j
If Worksheets(k).Name <> "master" Then
tot = tot + Worksheets(k).Range("A1")
End If
Next k
MsgBox tot
Worksheets("master").Range("A1") = tot
End Sub