Formulas Protection : Worksheet Protection « Excel « VBA / Excel / Access / Word






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

 








Related examples in the same category

1.Add protection to Worksheet
2.Protect Sheet
3.Unprotect worksheet
4.Show Protection Properties
5.remove user
6.Remove user edit range
7.Add user edit range
8.Protecting Worksheet Assets with the Protect Method