Lock the cells with the formulas

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

Hi ,

maybe u should try this (need to be adapted)

Private Sub Worksheet_Deactivate()
    Sheets(2).Rows("1:6").EntireRow.Hidden = True 'adapt it
End Sub

Private Sub Worksheet_activate()
    If InputBox("Your password : ", "password") = "pwd" Then 'adapt it
        Sheets(2).Rows("1:6").Select
        Selection.EntireRow.Hidden = False
        [A1].Select
    Else
        Sheets(1).Activate
    End If
End Sub

This code will ask for a password each time you open 2nd sheet and hide 6 first line.

Thanks Vince1512 for the quick response!

I do not want to enter a password in the box.

For example the password is "A1B2" - my intent is a permanent password for all sheets.

I'm not sure, if its what u need ... but try this

Private Sub Workbook_Open()
    For i = 1 To Sheets.Count
     Sheets(i).Protect Password:="pass"
    Next
End Sub

king

Search for threads similar to "lock formulas"