Hello everyone!
I would like to help, I need a VBA code to protect cells with formulas and will then lock the sheet with a password.
So far I've been able to write code that goes through all the sheets in the file and lock the cells with the formulas.
For password protection I could not
Thanks to the tortured.
This is the code I wrote:
Sub Lock()
'
' lock מאקרו
'
'
Dim i As Integer
Dim WS_Count As Integer
Dim x As Long
With ActiveWorkbook
'Loop through all sheets in the workbook
For x = 1 To .Sheets.Count
'Check if the sheet is visible
If .Sheets(x).Visible = xlSheetVisible Then
'Activate/select the sheet and exit the loop
.Sheets(x).Activate
Exit For
End If
Next x
End With
WS_Count = ActiveWorkbook.Worksheets.Count
For i = 1 To WS_Count
''''הסרת ההגנה הקיימת בגיליונות//Remove the existing protection in the sheets
ActiveSheet.Unprotect
'''''
Cells.Select
Range("DA1").Activate
Selection.Locked = False
Selection.FormulaHidden = False
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("A1").Select
ActiveSheet.Next.Select
Next i
End Sub