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

robgoldstein

Board Regular
Joined
Oct 26, 2013
Messages
103
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?
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,426
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:

robgoldstein

Board Regular
Joined
Oct 26, 2013
Messages
103
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.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,426
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:

robgoldstein

Board Regular
Joined
Oct 26, 2013
Messages
103
I want to prevent both, but most importantly I want to protect the code.
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,426
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.
 

Forum statistics

Threads
1,077,977
Messages
5,337,506
Members
399,153
Latest member
Tsmith25

Some videos you may like

This Week's Hot Topics

Top