Protecting Cells

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 :eeek:

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. :eeek::crash:

Any ideas on how to get this done ??
:(
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You need to select the entire sheet, Format > Cells > Protection tab, untick Locked.

Then your first code should work with this change

Rich (BB code):
Range(Cells(Target.Row, "N"), Cells(Target.Row, "O")).Locked = True
 
Upvote 0
I tried that,

I get a Debug error on this line

Range(Cells(Target.Row, "N"), Cells(Target.Row, "0")).Locked = True
However after making a few adjustments

Range(Cells(Target.Row, "N"), Cells(Target.Row, "O")).Locked = True
it works like a charm
 
Upvote 0
I tried it and i get a run time error of 1004 when i try to protect certain cells.

O FYI i am using Excel 2010..... and ideas ?
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top