breynolds0431
Active Member
- Joined
- Feb 15, 2013
- Messages
- 303
- Office Version
- 365
- 2016
- Platform
- 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