is there a way to password protect cells from being changed?

robgoldstein

Board Regular
Joined
Oct 26, 2013
Messages
165
Office Version
  1. 2019
Platform
  1. Windows
I have created a multi-sheet workbook with several VBA codes running and I want to make sure people can't mess it up. Is there a way to make sure people can only input information into certain cells and run the codes from the buttons?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Unlock the cells where you want to input data and lock those cells you don't want changed. Then protect the sheet. In order for your macros to run properly you will have to place your code between "unprotect" and "protect" as shown below:
Code:
Sub robgoldstein()
    ActiveSheet.Unprotect Password:="[COLOR="#FF0000"]MyPassword[/COLOR]"
    'your code here
    ActiveSheet.Protect Password:="[COLOR="#FF0000"]MyPassword[/COLOR]"
End Sub
Change "MyPassword" (in red) to match the password you use when protecting the sheet.
 
Last edited:
Upvote 0
Sonthisbwould require them to enter a password when they run the code.
I just want them to enter a password when they want to change the code.
 
Upvote 0
The sheet protection, with or without a password, prevents any changes in the cells that were locked. The macros will still run when you click the buttons without having to enter any password. I believe that is what you wanted. Did you want to prevent changes to certain cells or did you want to prevent changes to the code in the macros?
 
Last edited:
Upvote 0
I want to prevent both, but most importantly I want to protect the code.
 
Upvote 0
The instructions in Post #2 and the macro I suggested will protect the locked cells from being changed. To protect your code, you have to protect your VBA Project. Do the following:
-hold down the ALT key and press the F11 key to open the Visual Basic Editor
-click on 'Tools' on the top menu
-click 'VBAProject Properties'
-click the 'Protection' tab
-click the box to the left of 'Lock project for viewing' to put a check mark in it
-enter your password and then confirm it and click 'OK'
-close the VB Editor
-save your workbook as a macro-enabled file and close it
When you re-open the file, you will not be able to see the macros unless you enter the password. Keep in mind that this type of protection is not very strong and anyone who really wants to get at your macros can probably do it with a little research. I hope this helps.
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,254
Members
448,556
Latest member
peterhess2002

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