I have a workbook which contains sheets with formulas in some of the cells. I want to protect the cells containing these formulas from editing, but I don't want to protect the non-formula containing cells. When I save the worksheet I want the cell protection for the formulas to propagate to the new worksheet.
for example Consider my workbook A containing two sheets (Sheet1 and Sheet2).
Sub protect()
Dim pwd As String
pwd = InputBox("entrer a password", Title:="Password")
Worksheets("Sheet1").Activate
Worksheets("Sheet1").Copy
Cells.Select
Cells.SpecialCells(xlCellTypeFormulas).Locked = True
Worksheets("Sheet1").Protect pwd, True, True, True, True
ActiveWorkbook.SaveAs Filename:="myfile1"
ActiveWorkbook.Close
ThisWorkbook.Activate
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Copy
Cells.Select
Cells.SpecialCells(xlCellTypeFormulas).Locked = True
Worksheets("Sheet2").Protect pwd, True, True, True, True
ActiveWorkbook.SaveAs Filename:="myfile2"
ActiveWorkbook.Close
ThisWorkbook.Activate
End Sub
When I run this code all the cells (which contains formulas or not) of both "myfile1" and "myfile2" are protected. I only want to protect the cells which contain formulas.
How do I accomplish just protecting only the cells with formulas?