This macro will hide all formulas within a workbook and not allow them to be deleted. The page will not be protected like a regular protected worksheet in excel; this means that you can still add content to the workbook without a problem and you can edit everything as long as it is not a formula. You can enter a new formula but you cannot then delete that formula. In addition, if you select a cell with a formula, that cell's contents will not be displayed. This allows you to keep your formulas hidden from users and adds an extra level of security. If you want to edit a particular cell, you will have to click that cell and then "Unhide" that cell by typing a password (which is located in the VBA code). Also, if you decide to delete this macro from your workbook, you will have to re-enter the password to unprotect the workbook afterwards if you want everything to be unprotected.
Note: To change the password, locate where it says "password" in the macro vba code and change this word to any password you want. You will need to change this in three separate places within the macro.
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim formula As Range
On Error Resume Next
Sh.Unprotect Password:="password"
With Selection
.Locked = False
.FormulaHidden = False
End With
If Target.Cells.Count = 1 Then
If Target.HasFormula Then
With Target
.Locked = True
.FormulaHidden = True
End With
Sh.Protect Password:="password", UserInterFaceOnly:=True
End If
ElseIf Target.Cells.Count > 1 Then
Set formula = Selection.SpecialCells(xlCellTypeFormulas)
If Not formula Is Nothing Then
With Selection.SpecialCells(xlCellTypeFormulas)
.Locked = True
.FormulaHidden = True
End With
Sh.Protect Password:="password", UserInterFaceOnly:=True
End If
End If
On Error GoTo 0
End Sub