Sorry for the delayed response ... I cannot reply to posts on this forum (even though I can create new posts!
)
I played around with the code some more, and I was able to make it work. Here it is:
Sub Summary_All_Worksheets_With_Formulas()
Dim Sh As Worksheet
Dim Newsh As Worksheet
Dim myCell As Range
Dim ColNum As Integer
Dim RwNum As Long
Dim Basebook As Workbook
Dim LR As Long
Dim src As Range
Dim ws As Worksheet
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'Delete the sheet "Summary-Sheet" if it exist
Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Worksheets("Summary-Sheet").Delete
On Error GoTo 0
Application.DisplayAlerts = True
'Add a worksheet with the name "Summary-Sheet"
Set Basebook = ThisWorkbook
Set Newsh = Basebook.Worksheets.Add
Newsh.Name = "Summary-Sheet"
Newsh.Range("B1:H1").Value = Array("Study Number", "Unit Tracker Owner", "Group Lead", "Sponsor", "Backlog Remaining", "Forecast Cost", "Cost Exceeding Backlog", "Cost Exceeding Contract")
'The links to the first sheet will start in row 2
RwNum = 1
For Each Sh In Basebook.Worksheets
If Sh.Name <> Newsh.Name And Sh.Visible Then
ColNum = 2
RwNum = RwNum + 1
'Copy the sheet name in the A column
Newsh.Cells(RwNum, 1).Value = Sh.Name
For Each myCell In Sh.Range("L2").End(xlDown).Offset(2, 0) '<--Change the range
ColNum = ColNum + 4
Newsh.Cells(RwNum, ColNum).Formula = _
"='" & Sh.Name & "'!" & myCell.Address(False, False)
Next myCell
For Each myCell In Sh.Range("P2").End(xlDown).Offset(2, 0) '<--Change the range
ColNum = ColNum + 1
Newsh.Cells(RwNum, ColNum).Formula = _
"='" & Sh.Name & "'!" & myCell.Address(False, False)
Next myCell
For Each myCell In Sh.Range("Q2").End(xlDown).Offset(2, 0) '<--Change the range
ColNum = ColNum + 1
Newsh.Cells(RwNum, ColNum).Formula = _
"='" & Sh.Name & "'!" & myCell.Address(False, False)
Next myCell
End If
Next Sh
Newsh.UsedRange.Columns.AutoFit
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
'Format study numbers to have leading zeros
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:A" & LR).NumberFormat = "00000000"
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:A" & LR).HorizontalAlignment = xlHAlignLeft
Set src = Range("B1").CurrentRegion
Set ws = ActiveSheet
ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=src, _
xlListObjectHasHeaders:=xlYes, tablestyleName:="TableStyleMedium28").Name = "Sales_Table"
ws.Range("B:B").EntireColumn.Hidden = False
ws.Range("A:A").EntireColumn.Hidden = True
ws.Range("B2") = "=INDIRECT(""'"" & TEXT(A2,""00000000"") &""'!A2"")"
End Sub
Bookmarks