Getting a compile error when trying to unlock a sheet?

2022

Board Regular
Joined
Jun 5, 2022
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
Hi, I'm trying to use this code to unprotect a sheet (which is locked with a password - let's call it - ZXYD).

However, I'm getting a compile error at the point the code reaches this line.

Does anyone know why that would happen?

VBA Code:
ActiveSheet.Unprotect ZXYD
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try
VBA Code:
ActiveSheet.Unprotect "ZXYD"
 
Upvote 0
Thanks Fluff - that solved that problem!

When I re-ran the code, though, I got a "Compile error" at this point, where I'm trying to lock the content of cells again, before protecting the sheet again.

It said "wrong number of arguments or invalid property assignment"

Do you know why that would happen?

VBA Code:
Range("M2:XD10").Activate Selection.Locked = True
ActiveSheet.Protect Contents:=True
 
Upvote 0
Try
Excel Formula:
Range("M2:XD10").Locked = True
 
Upvote 0
Ok, I tried that.

However, when I ran the code, it stopped at one of the 'locked' columns.

So I tried to add

VBA Code:
Range("M2:XD10").Locked = False

right after the this line

VBA Code:
ActiveSheet.Unprotect "ZXYD"

ie

VBA Code:
ActiveSheet.Unprotect "ZXYD"
Range("M2:XD10").Locked = False

But then the code stopped at that point ie

VBA Code:
Range("M2:XD10").Locked = False

Do you know why that would happen?
 
Upvote 0
What error did it give?
 
Upvote 0
Run time error ‘1004’:

Unable to set the Locked property of the Range class.
 
Upvote 0
Make sure you do not have any merged cells.
 
Upvote 0
Ok, I’ll look into that. Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,859
Messages
6,121,963
Members
449,059
Latest member
oculus

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