Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through worksheets & calculate sum

Status
Not open for further replies.

robgee76

Technical User
Joined
Jul 15, 2003
Messages
1
Location
US
I have a workbook that will have a variable number of sheets in it.
I need to loop through the sheets (except one named "Example" and one named "Summary") and
calculate the sum of the values that are located in the same cell on each sheet (D42, for example).

I then want this result to be displayed on the summary sheet, in cell C3 for example.

Can anyone help me out?

Thanks.
 
This code will do it

Dim SumValue as Integer

SumValue = 0

For i = 1 To Sheets.Count
If Sheets(i).Name = "Example" or Sheets(i).Name = "Summary" Then
'do nothing
Else
Sheets(i).Activate
ActiveCell("A1").Select 'put reference to cell
'to be summed here

SumValue = SumValue + ActiveCell.Value
EndIf
Next i

Sheets("Summary").Activate

ActiveCell("A1").Select 'put reference to cell
'to hold summary here

ActiveCell.Value = SumValue

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top