Is it possible to copy and rename a hidden sheet?
I've created the macro as below
Sub Copyandrename()
'
' Copyandrename Macro
'
'
Sheets("Template").Copy Before:=Sheets(1)
Sheets("Template (2)").Name = "Issues and Key Takeaways"
Rows("6:6").Select
Range("C6").Activate
Selection.AutoFilter
ActiveWorkbook.Worksheets("Issues and Key Takeaways").AutoFilter.Sort. _
SortFields.Clear
ActiveWorkbook.Worksheets("Issues and Key Takeaways").AutoFilter.Sort. _
SortFields.Add Key:=Range("C6"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Issues and Key Takeaways").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D9").Select
End Sub
However once I hide the 'Template' tab, I'll get the following error.
Run-time error '91':
Object variable or With block variable not set
Any suggestions to fix the issue?