I'll do my best to explain. Need help creating a summary page using a macro crafted by JBeaucaire that creates worksheets in a workbook generated by a column of location names that are entered by various managers. The number of locations and their respective names are unknown. However, the worksheets created are essentially copies of a template called "Master" and the worksheet with the location names is called "Locations". I'm looking to add up the same totals for all of worksheets, except "Locations" and "Master" which appear in column "BD" starting with cell BD8 on all of the copied sheets and have the totals appear in column "C" starting with cell C8 on the "Summary Page". I did some minor tweaking to the code that JBeaucaire provided below:
Option Explicit
Sub AddNamedSheets()
Dim NmRNG As Range, Nm As Range
If Sheet2.Range("A1").Value = Empty Then
MsgBox "Please Enter Location Name"
Exit Sub
End If
'Application.ScreenUpdating = False
'Sheets("Master").Visible = True
On Error Resume Next
Set NmRNG = Sheets("Locations").Range("A3:A41").SpecialCells(xlConstants)
If NmRNG Is Nothing Then
MsgBox "Depot List empty, please add location"
Exit Sub
End If
For Each Nm In NmRNG
'make sure the sheet doesn't exist already
If Not Evaluate("ISREF('" & Nm.Value & "'!A1)") Then
Sheets("Master").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = Nm.Value
ActiveSheet.Cells(5, 2) = Nm.Value
End If
Next Nm
'Sheets("Master").Visible = False
'Application.ScreenUpdating = True
'Sheet1.Visible = xlSheetVeryHidden
End Sub
Any help is appreciate. I wasn't sure if I could use for example: Sum('Sheet4:Sheet41'BD8) seeing that I wouldn't know how many sheets would be created; the maximum number of sheets is 41.
The code that I was trying to use to create the Summary Page is, but it only totals the last entry on the locations worksheet ignoring all others:
Sub CopyToSummary()
Dim OutSH As Worksheet
Set OutSH = Sheets("Summary")
For Each sh In Worksheets
If sh.Name <> "Summary" Then
sh.Range("bd8:BD87").Copy
OutSH.Cells(8, 3).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste link:=True
End If
Next sh
End Sub
Bookmarks