Sub protect()
Range( "A3:A12,D3:E12,J1:R13,S3:S11,W18").Select
Range("W18").Activate
Selection.Locked = True
ActiveSheet.protect Contents:=True
End Sub
Then I use this code to add a new worksheet:
Sub AddNewSheet()
ActiveSheet.Unprotect
Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Call protect
End Sub
When the protect routine runs the very first time, it works fine. But when
I unprotect the cells in the AddNewSheet routine, they never get
re-protected nor do the cells in the copied sheet get protected. I'd
appreciate any help. Thanks very much.
Tom
Sub Macro1()
Application.ScreenUpdating = False
Dim ws As Worksheet
With Sheets("Sheet1")
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas, 23).Locked = True
.Cells.SpecialCells(xlCellTypeFormulas, 23).FormulaHidden = True
Set ws = Sheets.Add
.Cells.Copy ws.Range("A1")
End With
With ws
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas, 23).Locked = True
.Cells.SpecialCells(xlCellTypeFormulas, 23).FormulaHidden = True
.Protect
End With
Sheets("Sheet1").Protect
Application.ScreenUpdating = True
end sub
Regards
William
willw...@yahoo.com
"Tom Carlson" <tcarl...@earthlink.net> wrote in message
news:uHB9fZS0AHA.2324@tkmsftngp02...
The code can be simplified to this
Sub Macro1()
Application.ScreenUpdating = False
Dim ws As Worksheet
With Sheets("Sheet1")
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas, 23).Locked = True
.Cells.SpecialCells(xlCellTypeFormulas, 23).FormulaHidden = True
Set ws = Sheets.Add
.Cells.Copy ws.Range("A1")
ws.Protect
.Protect
End With
Application.ScreenUpdating = True
End Sub
"William" <willw...@yahoo.com> wrote in message
news:u9TBXpS0AHA.1364@tkmsftngp05...
See these changes on your Sub:
Sub AddNewSheet()
Dim FirstSh As Worksheet
Set FirstSh = ActiveSheet
ActiveSheet.Unprotect
Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Call protect
FirstSh.Select
ActiveSheet.protect Contents:=True
End Sub
HTH
--
Orlando Magalhães Filho
Santa Quitéria-Ce, Brazil
Microsoft MVP - Excel
"Tom Carlson" <tcarl...@earthlink.net> escreveu na mensagem
news:uHB9fZS0AHA.2324@tkmsftngp02...