How to Lock Cells With Formulas and Protect Sheet using VBA

Learn In 5 Minutes
Learn In 5 Minutes
2.4 هزار بار بازدید - 4 سال پیش - In this tutorial you will
In this tutorial you will learn how to lock cells with formulas and protect sheet using VBA macro programming in Microsoft Excel

VBA Code Without Password:
'This macro code will lock all the cells with formulas
Sub LockFormulasProtectSheet()
   With ActiveSheet
      .Unprotect
      .Cells.Locked = False
      .Cells.SpecialCells(xlCellTypeFormulas).Locked = True
      .Protect AllowDeletingRows:=True
   End With
   MsgBox ("Formulas are locked successfully")
End Sub

VBA Code With Password:
'This macro code will lock all the cells with formulas
Sub LockFormulasProtectSheet()
   Dim password As String
   password = "Pass123"
   With ActiveSheet
      .Unprotect password:=password
      .Cells.Locked = False
      .Cells.SpecialCells(xlCellTypeFormulas).Locked = True
      .Protect password:=password, AllowDeletingRows:=True
   End With
   MsgBox ("Formulas are locked successfully")
End Sub
4 سال پیش در تاریخ 1399/07/15 منتشر شده است.
2,497 بـار بازدید شده
... بیشتر