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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

Code:
Sub copysheet()
Sheet1.copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Visible = xlSheetVisible
End Sub
 
Upvote 0
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
 
Upvote 0
What error did you get and on which line of code.

It worked for me when I tested it.
 
Upvote 0
runtimeerror 1004
method copy of object worksheet failed

and "Sheet1.Copy after:=Sheets(Sheets.Count)" is highlighted
 
Upvote 0
The only way I can reproduce that is if the workbook is protected. Is it?
 
Upvote 0
Yes, that sheet is protected
But, as I said, when Sheet1 is visible, this works just fine
Sheet must be protected :biggrin:
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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