looping through worksheets and extracting autosum information

grapevine

Board Regular
Joined
May 23, 2007
Messages
208
I have created a macro that produces between 20 and 40 sheets of data depending on the source data and the sheets are named with a town and then either list or labels. eg "ipswich labels" then "ipswich list" then "norwich lables" "norwich list" etc continuing through many different towns. Each sheet called labels contains numeric data in column A. The heading at the top of column A is labelled QTY. The first 7 pages of the workbook contain other information so I am hoping that the For statement is correctly telling the system to count from worksheet 8 onwards.

After the macro has created the various sheets I would like to create a summary page called Totals which in column A puts the sheet name and in column b puts the total of the numeric data in column A, so that I have a list of all the towns and the total number allocated to that town. eg in A1 ipswich in B1 323, in A2 norwich in B2 221 etc

I have not yet tried to bring over the sheet name, but firstly I was trying to get a macro to loop through the various pages to do an autosum on column A and put that value on the Totals Page, (I do not need the total on the individual pages) but I am having problems trying to get the macro to move through the different pages. The line which is causing problems is the If Line as I cannot work out how to tell it to go to the correct place on the first sheet it comes across.
I would be grateful for any help to point me on the way and if there is a way to bring over the sheet name as well I would be really delighted.

Many, many thanks in advance

Sub Totals()
Dim worksheetcount As Integer
Dim WS As Worksheet
Dim rw As Long
rw = Range("A65536").End(xlUp).row

Sheets("Totals").Activate
Range("B2").Select
For worksheetcount = 8 To Worksheets.Count

If WS.Range(R1c1) = "QTY" Then

ActiveCell.FormulaR1C1 = "=sum(activesheet!r2c1:rw&c1)"
Rows(row).Offset(1, 0).Select
Else
End If
Next worksheetcount

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try like this - it assumes that Totals is the last sheet

Code:
Sub Totals()
Dim i As Long
With Sheets("Totals")
For i = 8 To Worksheets.Count - 1
    .Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets(i).Name
    .Range("B" & Rows.Count).End(xlUp).Offset(1).Value = WorksheetFunction.Sum(Sheets(i).Columns("A"))
Next i
End Sub
 
Upvote 0
What a superstar and such simple coding as well. I shall put this into action straightaway.
Many many thanks.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top