Here is the code to create a duplicate "Outyear" or worksheet:
Sub Outyears()
Dim CurrentYear As Integer, NewName As String
If IsNumeric(Right(ActiveSheet.Name, 2)) Then
CurrentYear = Right(ActiveSheet.Name, 2)
ElseIf IsNumeric(Right(ActiveSheet.Name, 1)) Then
CurrentYear = Right(ActiveSheet.Name, 1)
Else
Exit Sub
End If
If CurrentYear >= 30 Then
MsgBox "You cannot go higher than 30"
Exit Sub
End If
CurrentYear = CurrentYear + 1
NewName = "20" & CurrentYear
Dim checkWs As Worksheet
On Error Resume Next
Set checkWs = Worksheets(NewName)
If checkWs Is Nothing Then
Worksheets(ActiveSheet.Name).Copy After:=Worksheets(ActiveSheet.Index)
ActiveSheet.Name = NewName
Else
Set checkWs = Nothing
MsgBox "A Worksheet named " & NewName & " already exists."
End If
End Sub
Here is the code I'm using which allows the group/ungroup function to be active within the protected sheet:
Private Sub Workbook_Open()
With Worksheets("2015")
.protect Password:="2015", Userinterfaceonly:=True
.EnableOutlining = True
End With
End Sub