I have the following code that adds all of the values of column BD (cells BD8:BD100) from various worksheets (user defined) and totals the results onto a Summary page column C (cells C8:C100).
The problem occurs when Sheet(4) doesn't exist.![]()
Sub CopyToSummary() Dim ws2 As String, wsLast As String ws2 = Sheets(4).Name wsLast = Sheets(Sheets.Count).Name With Sheets(3) .Range("c8:c100").Formula = "=SUM('" & ws2 & ":" & wsLast & "'!bd8)" End With End Sub
A Run-time error '9': Subscript out of range error results when the user attempts to run a summary report from the Summary tab when no Sheet4 exists. The following line of code is highlighted in yellow: ws2 = Sheets(4).Name
Is there a way to rewrite the code so that a message box appears directing the user to create a worksheet from the location tab and enter the respective quantities if a location worksheet "Sheet(4)" hasn't been created or possibly check to see if "Sheet (4)" exists and if it doesn't direct the user to create a worksheet from the location tab?
I hope I'm making sense or that the attached file better illustrates what I'm attempting.
Thanks in advance for any assistance provided.
Bookmarks