hello Davesexcel, thanks a lot for your response however, I tried it but getting an error.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim blnUnlockedAllCells As Boolean
Const RangeToLock As String = "A2:D1000" '<< adjust to suit
If Target.Cells.Count > 1 Then Exit Sub
If Not blnUnlockedAllCells Then
Me.Cells.Locked = False
On Error Resume Next
Me.Range(CStr(RangeToLock)).SpecialCells(2).Locked = True
On Error GoTo 0
blnUnlockedAllCells = True
Me.Protect Password:="pwd", userinterfaceonly:=True
End If
If Not Application.Intersect(Target, Me.Range(CStr(RangeToLock))) Is Nothing Then
If Len(Target) Then Target.Locked = True
End If
End Sub
and event I tired a new code as well but its not going with the BeforeSave event could you please help?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Worksheet: Set ws = ActiveSheet
ActiveSheet.Unprotect Password:="test"
If Not Intersect(Target, Range("F:F", "G:G")) Is Nothing Then
If Target.Value <> vbNullString Then Target.Locked = True
End If
ActiveSheet.Protect Password:="test"
End Sub
Bookmarks