Here is the code for creating a new week (worksheet) in my workbook. One of a number of similar command buttons that needs to unprotect and re-protect sheets.
- Private Sub AddWeek_Click()
-
Dim Week_of, week, Prev_week, prev_bal As String, num As Integer
-
num = 0
-
ActiveWorkbook.Unprotect
-
For Each ws In Worksheets
-
num = num + 1
-
Next ws
-
Prev_week = Sheets(num).Name
-
prev_bal = "='" & Prev_week & "'!K3"
-
week = month & "/" & day & "/" & year
-
Week_of = month & "_" & day & "_" & year
-
Sheets("Template").Select
-
Sheets("Template").Copy After:=Sheets(num)
-
Sheets("Template (2)").Select
-
Sheets("Template (2)").Name = Week_of
-
ActiveSheet.Unprotect
-
Sheets(Week_of).Range("H3").Formula = prev_bal
-
Sheets(Week_of).Range("H3").Select
-
Selection.Copy
-
Sheets(Week_of).Range("H4").Select
-
Sheets(Week_of).Range(Selection, Selection.End(xlDown)).Select
-
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
-
SkipBlanks:=False, Transpose:=False
-
Sheets(Week_of).Range("V1").Select
-
ActiveCell = "Attendance Records for the week of " & week
-
Sheets(Week_of).Range("B3").Select
-
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
-
ActiveWorkbook.Protect Structure:=True, Windows:=False
-
Unload Me
-
End Sub
Note: month, day and year are input from a form
I do not specify a range for the protection in each sheet for 2 reasons:
a) The range is in the copied sheet "Template"
b) Specifying a range kept giving me an error message
But the desired range is kept throughout all sheets.
I didn't know that the tab key worked only in the selected range (which makes sense), but regardless it is not working in that range either.
Just protecting the sheet in excel produces the same result, the tab key won't work. Excel 2002 is being used.
Hopefully this is enough info.