Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Formulas Protection

Sub ProtectFormulas()     Dim ws As Worksheet, rng As Range     Set ws = ThisWorkbook.Sheets("Protection")     ws.Unprotect     ' Get each used cell in the worksheet.     For Each rng In ws.UsedRange         ' If it contains a formula, lock the cell.         If InStr(rng.Formula, "=") Then             rng.Locked = True         ' Otherwise unlock the cell.         Else             rng.Locked = False         End If     Next     ws.Protect "Excel2003" End Sub