Potecting cells in a worksheet while allowing userform to add data

Jmwend

New Member
Joined
Aug 22, 2011
Messages
17
I have several worksheets in a workbook, one of which is a database worksheet. I am trying to protect the database worksheet from users editing cells while still allowing a userform on one of the seperate sheets to input the data into the database worksheet.

I have tried to protect the database sheet through tools>Protection>protect sheet. However, then when the data is inputed into the userform an error comes up saying that the other worksheet is protected so it cannot add the data.

Please let me know if this is possible and how it can be accomplished. Thank you in advance!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try including UserInterfaceOnly. This allows running code to plant data, whilst leaving the sheet protected.

Code:
[sheet Codename].Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
 
Upvote 0
Where would I input this code? Do I right click on the sheet that I want to protect and click view code and then put this code into that sheets code? Because I tried that and its not protecting the sheet. Do I include the brackets around the sheet code name? Lets say the sheet that I want to protect is called "Data Log" would my code look like this:

[Data Log].Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
 
Upvote 0
Sorry, the brackets were to demonstrate what was needed, not literal. To use the worksheet name (as shown on the worksheet's tab) use the first one below. To use the worksheet's codename, let's presume we changed the codename as shown and use the second. The codename is the upper of the two Name properties showing in the Properties window of VBIDE (where you are after right-clicking the sheet and choosing View).
Rich (BB code):
ThisWorkbook.Worksheets("Data Log").Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
shtDataLog.Protect Password:="MyPassword", DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True

Try putting it in the userform's Initialize event.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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