Macro button that copies hidden worksheet and changes name

jackson1990

Board Regular
Joined
Feb 21, 2017
Messages
56
Hey fellow forum posters,

So, I've shifted my focus to a different approach from what I was thinking before. Now I have a macro button. I already have it set to check if D1 contains 1 and if it does to make the copy, as well as making a copy then switching to that copy view. What I want it to do is make a copy of a hidden sheet (sheet2 in this case) that will be not hidden, rename it to template, and switch the view to that. I'm about half way there, but don't quite understand how I get it to copy a hidden sheet to produce a not hidden sheet, as well as renaming it (as it current is just naming it Sheet2 (2). Any help would be greatly appreciated. I've provided my Macro code yet far.

Code:
Sub Test4()'
' Test4 Macro
'


'
 If (Range("D1") = "1") Then
    Dim ws1 As Worksheet
    Set ws1 = ThisWorkbook.Worksheets("Sheet2")
    ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
    Sheets("Sheet2 (2)").Select
    End If
End Sub

Thanks for any help!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Code:
[color=darkblue]Sub[/color] Test4()
    [color=darkblue]If[/color] (Range("D1") = "1") [color=darkblue]Then[/color]
        Application.ScreenUpdating = [color=darkblue]False[/color]
        [color=darkblue]With[/color] ThisWorkbook.Worksheets("Sheet2")
            .Visible = xlSheetVisible
            .Copy After:=Sheets(Sheets.Count)
            .Visible = xlSheetHidden
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        ActiveSheet.Name = "Template"
        Application.ScreenUpdating = [color=darkblue]True[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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