Protecting a worksheet

TheShaunMichael

Board Regular
Joined
Oct 24, 2009
Messages
57
I have created a worksheet that is controlled entirely by buttons and userforms. How can I protect it so nobody can change the worksheet name and/or alter the cells/rows manually? The userforms will change/delete/insert rows and information though...
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try

Code:
Sheets("Sheet1").Protect Password:="abc", userinterfaceonly:=True

To prevent the user changing the sheet name you'll need to protect the workbook.
 
Upvote 0
You can set the protection in a ws_activate macro that flags the sheet as "OK" to edit with macros only when it is activated.

1) Right-click on the sheet tab and select VIEW CODE
2) Paste in this activation macro:
Code:
Private Sub Worksheet_Activate()
    Me.Protect "password", UserInterfaceOnly:=True
End Sub
 
Upvote 0
I pasted what you both wrote and I was still able to edit cells so I added "allowformattingcells:=false" and it works great!

Now, do you know if there's a way to be able to select a row but not be able to edit it or anything like that?

Thanks!
 
Upvote 0
1) Turn on the macro recorder
2) Now let the recorder record YOU as you go through the Tools > Protection > Protect Sheet and set the flags the way you want them.
3) Turn off the recorder
4) Examine the code to get the flags you want and add them to your code.

The recorder will not show the UserInterfaceOnly flag nor the password, you'll have to put those in yourself with the syntax we've already shown.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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