run time error 1004 - unprotect method of worksheet class failed

eat_cress

New Member
Joined
Dec 5, 2010
Messages
37
Hey guys,
I don't suppose anyone here is able to help me out with a problem I am having. I have a worksheet with the following code:
PHP:
Private Sub Worksheet_Calculate()
If ActiveSheet.ProtectContents Then
ActiveSheet.Unprotect "password123"
........loads of IF calculation which work fine......
 
 ActiveSheet.Protect "password123", True
 
 End If
 
End Sub
Anyway, when it does the first loop of calculations, it goes through fine. When it does the calculations of the sheet again. I get the run time 'error 1004 - unprotect method of worksheet class failed' message come up. It seems to me that It is able to unlock the sheet, and do the calculations, but when it locks it again it is using different settings or something, which means when it goes through it again with the standard 'ActiveSheet.Unprotect "password123"' line, its not unlocking it fully, or using the same criteria. as a result it is not unlocking the same.
Can any of you guys tell me where I am going wrong. I am using Excel 2003 unfortunately.
Many thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
replace all ActiveSheet. references with Me. references.
I think the ActiveSheet is not what you expect it to be at some point in the process. With 'Me', you will always refer to the worksheet where the event occurred...
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

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