Copy Sheets With at least one Table

breynolds0431

Active Member
Joined
Feb 15, 2013
Messages
303
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello. I am trying to copy out a set of worksheets to a new book. The problem I'm running into is the excel limitation of copying out a sheet with a table, which I had no previous idea that there was such a limitation. Specifically, the runtime states "You cannot copy or move a group of sheets that contain a table." Is there a way to do this in the below code? I'm thinking of checking the For Each ws to determine if the worksheet contains a ListObject, but I'm not exactly sure how to do so or if that would be efficient at all. Appreciate any attention given to this question!

VBA Code:
Private Sub CbtnDONE_Click()

Dim ws As Worksheet
Dim ShtCnt As Long

If Me.cboSheets.Value = "" Or Me.cbExpPrint.Value = "" Then
    MsgBox "Please complete both questions before continuing.", vbInformation, "Missing Response"
    Exit Sub
End If

Dim pop As String: pop = Me.cboSheets.Value ' The data set to copy

If Me.cbExpPrint.Value = "Export" Then
    ShtCnt = 0
    For Each ws In ActiveWorkbook.Worksheets
      If ws.Visible = xlSheetVisible And ws.Name Like pop & "-*" Then
        ShtCnt = ShtCnt + 1
        ws.Select False
      End If
    Next ws
    ActiveSheet.Copy '<<< Where the error ocurrs due to there being at least one sheet with a table
End if
End sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I am not sure that grouping the sheets before copying them is actually much faster than doing them one at time.
Copying the worksheets with tables should work fine if you copy the sheets 1 at a time.
 
Upvote 0

Forum statistics

Threads
1,215,351
Messages
6,124,445
Members
449,160
Latest member
nikijon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top