Run-time error '1004'; Unable to set the Locked property of the Range class

WatfordKev

Board Regular
Joined
Mar 30, 2011
Messages
78
I've read as much as I can on this but to little avail.

I have a Workbook which I want to update in VB code. It's on a protected sheet, which I unprotect, make the changes, protect again and this all seems to work until I then want to unlock a few cells for my colleagues to have access too.

Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

ActiveSheet.Unprotect "password"

If Range("D80").Value >= "Green" Then
Range("E83").Interior.ColorIndex = 4
Else
EndIf

If Range("D81").Value >= "Green" Then
Range("E84").Interior.ColorIndex = 4
Else
EndIf

Application.EnableEvents = True

ActiveSheet.Protect "password"

' this is where I get the 1004 message! Next statement!

ActiveSheet.Range("D80:D84").Locked = False ' unlock the cells
ActiveSheet.Range("F80:F84").Locked = False ' unlock the cells

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You need to set the Locked property before protecting. Try

Code:
' this is where I get the 1004 message! Next statement!

ActiveSheet.Range("D80:D84,F80:F84").Locked = False ' unlock the cells

ActiveSheet.Protect "password"
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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