Results 1 to 4 of 4

[Solved] Help creating a Summary Page from user-defined worksheets

Threaded View

  1. #1
    Registered User
    Join Date
    07-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    37

    [Solved] Help creating a Summary Page from user-defined worksheets

    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).

    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
    The problem occurs when Sheet(4) doesn't exist.
    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.
    Attached Files Attached Files
    Last edited by gophil1; 08-17-2012 at 12:59 PM. Reason: Solution found

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1