VBA Code Won't Run when I Protect Worksheet

USFengBULLS

Board Regular
Joined
May 7, 2018
Messages
66
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am sure this is an easy question but would anyone know why I am getting a 1004 Runtime Error in my Code after I protected the Worksheets from the review Tab?
The code works fine when the sheets are unprotected, but I need to protect the worksheets so users can not adjust the formulas and contents of certain/most cells.
My code does work with a lot of these cells that are locked once Protected but I can't figure out why I am getting this Runtime 1004 error now.
Any Suggestions? Thanks.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Place your code between these 2 lines:

Code:
Activesheet.Unprotect
'your code here
Activesheet.Protect


This will unprotect the sheet, run the code and then protect it again.
 
Upvote 0
Okay, but I broke it up into 4 different codes in my Module. Then use the Call function on the command button activeX and run all four at once.
How would that work?
 
Upvote 0
Hi,
Use these statements in command button module

Activesheet.Unprotect
Call macro1
Call macro2
Call macro3
Call macro4
Activesheet.protect

Regards,
Sebastian
 
Upvote 0
I just did that and used sheet3.Unprotect for the sheet the code copies content to from the active sheet. When I click the ActiveX Command Button it asks for the password for both sheets.
 
Upvote 0
You did not mentioned you've got worksheets password protected. Use this...

Activesheet.Unprotect password:="Type in your password"
Call macro1
Call macro2
Call macro3
Call macro4
Activesheet.protect password:="Type in your password"
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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