excelheadjay
New Member
- Joined
- Oct 23, 2010
- Messages
- 5
Hi,
I have a work book in which i have a number of cells, I want to be able to protected certain cells in the same row one a field contains a certain data is entered in a Cell in Column P, what i want to happen is once Column P is Changed to "Y" it looks the respective cells in columns N and O to be protected.
I am currently using this Macro
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("P:P")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here)
If Target.Value = "Y" Then
ActiveSheet.Unprotect "PasswordGoesHere"
Range(Cells(Target.Row, "N"), Cells(Target.Row, "0")).Locked = True
ActiveSheet.Protect "PasswordGoesHere"
End If
End Sub
However this Macro Locks the entire sheet. I only want it to lock that specific ROW
I.E.
If Cell P1 is Y then the Macro should Lock N1 and O1 "ONLY".
I have tried editing the Macro as follows.
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("P1")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here)
If Target.Value = "Y" Then
ActiveSheet.Unprotect "PasswordGoesHere"
Range(Cells(Target.Row, "N1"), Cells(Target.Row, "01")).Locked = True
ActiveSheet.Protect "PasswordGoesHere"
End If
End Sub
However this still does the same thing.
Any ideas on how to get this done ??
I have a work book in which i have a number of cells, I want to be able to protected certain cells in the same row one a field contains a certain data is entered in a Cell in Column P, what i want to happen is once Column P is Changed to "Y" it looks the respective cells in columns N and O to be protected.
I am currently using this Macro
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("P:P")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here)
If Target.Value = "Y" Then
ActiveSheet.Unprotect "PasswordGoesHere"
Range(Cells(Target.Row, "N"), Cells(Target.Row, "0")).Locked = True
ActiveSheet.Protect "PasswordGoesHere"
End If
End Sub
However this Macro Locks the entire sheet. I only want it to lock that specific ROW
I.E.
If Cell P1 is Y then the Macro should Lock N1 and O1 "ONLY".
I have tried editing the Macro as follows.
Private Sub Worksheet_Change(ByVal Target As Range)
' Code goes in the Worksheet specific module
Dim rng As Range
' Set Target Range, i.e. Range("A1, B2, C3"), or Range("A1:B3")
Set rng = Target.Parent.Range("P1")
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
' Action if Condition(s) are met (do your thing here)
If Target.Value = "Y" Then
ActiveSheet.Unprotect "PasswordGoesHere"
Range(Cells(Target.Row, "N1"), Cells(Target.Row, "01")).Locked = True
ActiveSheet.Protect "PasswordGoesHere"
End If
End Sub
However this still does the same thing.
Any ideas on how to get this done ??