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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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