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
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,770
Messages
5,513,312
Members
408,945
Latest member
gravy834

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top