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

robgoldstein

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

Some videos you may like

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.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,121
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
146
Office Version
  1. 2019
Platform
  1. Windows
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
10,121
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
146
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

I want to prevent both, but most importantly I want to protect the code.
 

mumps

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

robgoldstein

Board Regular
Joined
Oct 26, 2013
Messages
146
Office Version
  1. 2019
Platform
  1. Windows
Thanks so much. That is exactly what I wanted.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,737
Messages
5,597,826
Members
414,180
Latest member
Sir Khaya

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
Top