"Copy method of Sheets class failed" VBA error

mrlex

New Member
Joined
Sep 4, 2013
Messages
10
Hi all, I am trying to create a formula that will copy a worksheet from my activeworkbook to a new document and save.

I have the below code, but when I run it I get an error:

"Copy method of Sheets class failed"

The sheet is not protected (which was my first guess). Any idea how to solve this?

Code:
Sub SampleMacro()
Dim FName As String
Dim Sh As Worksheet


Application.ScreenUpdating = False


FName = "MyBook" & Format(Now(), "dd-mmm-yyyy") 


If Dir("C:\" & FName & ".xlsx") = vbNullString Then
[B][COLOR=#ff0000]    Sheets(Array("Form", "Updates")).Copy [/COLOR][/B]
        For Each Sh In ActiveWorkbook.Worksheets
            With Cells
                .Copy
                .PasteSpecial xlPasteValues
                .PasteSpecial xlPasteColumnWidths
            End With
            Range("A1").Select
        Next Sh
    ActiveWorkbook.SaveAs "C:\" & FName & ".xlsx", xlNormal
End If
     
Application.CutCopyMode = False
Application.ScreenUpdating = False
     
End Sub

 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi mrlex,

Are you trying to copy one worksheet named "Form Updates", or two worksheets named "Form" and "Updates"?

Your description mentions "... copy a worksheet...", but the code is trying to find two worksheets.
 
Upvote 0

Forum statistics

Threads
1,215,970
Messages
6,127,991
Members
449,414
Latest member
sameri

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