• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Automatically lock a cell after inputed data

Wagbo

New Member
Hi All

I am trying to protect a cells value once it has been input
The code I am using works. However, it stop the user from using the auto filter function
This is the code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As RangeOn Error Resume NextSet xRg = Intersect(Range("A1:F8"), Target)
If xRg Is Nothing Then Exit Sub
Target.Worksheet.Unprotect Password:="123"
xRg.Locked = True
Target.Worksheet.Protect Password:="123"
End Sub

Can anyone help me to protect the cell and still use the auto filter
Thanks in advance
 
Hi, I got that from the initial post. Please check the options manually. Then try your code again.
I think it will work then.
 
I have tried to do it manually but when the vba locks the cell it reverts back to the original state. I think the code is telling it to lock everything. Maybe I need a another line somehow telling to allow filter
 
with macro recorder I got
Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
  , AllowFiltering:=True
 
Just been testing out and all works well but you can unprotect the cells without a password any ideas
 
Back
Top