Help with VBA

[Solved/Closed]
Report
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
-
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
-
Hello,


I'm trying to program a macro in Excell 2010. What I need it to do is look in a Range for the NotEmptyCells and change their property from Unlocked to Locked. It's my firs time working with VBA so any help will be appreciatted. Thanks!

2 replies

Posts
7098
Registration date
Saturday April 7, 2007
Status
Moderator
Last seen
June 10, 2021
488
Hello,

I put as password "12345" and I took a plage of cells "A2:C30" for example (you can change them into the macro) :

Private Sub Worksheet_Change(ByVal Target As Range) 
If Not Intersect(Target, Range("A2:C30")) Is Nothing Then 
ActiveSheet.Unprotect Password:="12345" 
Target.Locked = True 
ActiveSheet.Protect Password:="12345" 
End If 
End Sub


Regards

"Pour trouver une solution à ses problèmes, il faut s'en donner la peine."
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2821 users have said thank you to us this month

Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012

It was perfect! Thanks a lot for your help! :)