+ Reply to Thread
Results 1 to 5 of 5

Error Handling on Copy Sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Error Handling on Copy Sheets

    Hi, The code below runs the first If statement even if sheets are visible. How do I check if no sheets are visible to make this work? (If I remove the first If statement, the remainder works as it should, but there is no copy made if there are no visible sheets and no error message.)

    Dim ws As Worksheet
    For Each ws In Worksheets
        
        If ws.Name <> "Select" And ws.Visible = False Then
            MsgBox "No worksheets available to copy - please make selections using the Open Selection Form button."
            Exit Sub
            
            ElseIf ws.Name <> "Select" And ws.Visible = True Then
                ws.Copy
                    Cells.Select
                    Selection.Rows.AutoFit
                    Rows(1).RowHeight = 65
                    Range("A1").Select
            End If
        Next
    Last edited by ker9; 12-03-2011 at 11:30 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error Handling on Copy Sheets

    I hope i got it right.
    Last edited by Kelshaer; 12-01-2011 at 11:31 AM.

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error Handling on Copy Sheets

    Dim ws As Worksheet
    Dim chkExist As Boolean
    For Each ws In Worksheets
    
        If ws.Name <> "Select" And ws.Visible = True Then
            chkExist = True
            ws.Copy
            Cells.Select
            Selection.Rows.AutoFit
            Rows(1).RowHeight = 65
            Range("A1").Select
            Exit For
        End If
    Next
    
    If chkExist = False Then
        MsgBox "No worksheets available to copy - please make selections using the Open Selection Form button."
    End If

  4. #4
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Error Handling on Copy Sheets

    Perfect! Thank you. (Sorry I took so long responding - end of the month demands a complete refocus of attention.)

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error Handling on Copy Sheets

    Please Mark the thread as SOLVED

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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