copy sheet macro problem

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
Hi to all

I have recorded macro which copy Sheet1
That works fine until Sheet1 is veryhidden
Sheet1 suppose to be veryhidden cause its template sheet
So, when user fill up sheet2 he need to press button and he will get Sheet1, named Sheet3, u know how that works

I tried avoid that by this:

Code:
Sub copy()
Sheet1.Visible = xlSheetVeryHidden = False
    Sheets("Sheet1").Select
    Sheets("Sheet1").Copy Before:=Sheets(1)
Sheet1.Visible = xlSheetVeryHidden = True
End Sub

That didn't help me, I get part "Sheets("Sheet1").Select" colored yellow

I don't know how to fix this, can someone help me?

Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub copysheet()
Sheet1.copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Visible = xlSheetVisible
End Sub
 

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
I didn't get desired result
I get error again :confused:

After pressing the button, sheet1 need to be copied to the start of workbook and must remain hidden, so new sheet will have name Sheet1(2)

When Sheet1 is visible, it works perfectly
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
What error did you get and on which line of code.

It worked for me when I tested it.
 

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591

ADVERTISEMENT

runtimeerror 1004
method copy of object worksheet failed

and "Sheet1.Copy after:=Sheets(Sheets.Count)" is highlighted
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
The only way I can reproduce that is if the workbook is protected. Is it?
 

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591

ADVERTISEMENT

Yes, that sheet is protected
But, as I said, when Sheet1 is visible, this works just fine
Sheet must be protected :biggrin:
 

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
Oh, workbook is not protected (as I know, and I should know cause I made it:biggrin:)
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Apologies - it does error if the sheet is very hidden, not just hidden. Try

Code:
Sub copysheet()
Application.ScreenUpdating = False
With Sheet1
    .Visible = xlSheetVisible
    .copy after:=Sheets(Sheets.Count)
    .Visible = xlSheetVeryHidden
End With
Application.ScreenUpdating = True
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,398
Messages
5,831,405
Members
430,064
Latest member
Shahrukh kha

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
Top