Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protecting cells in Excel but allow these to be modified by VBA script

Tags:

excel

vba

I am using Excel where certain fields are allowed for user input and other cells are to be protected. I have used Tools Protect sheet, however after doing this I am not able to change the values in the VBA script. I need to restrict the sheet to stop user input, at the same time allow the VBA code to change the cell values based on certain computations.

like image 847
Dheer Avatar asked Sep 24 '08 04:09

Dheer


People also ask

Can VBA edit protected cells?

If the UserInterfaceOnly parameter is set to true, VBA code can modify protected cells. This is a better solution, of course.

Can macros edit protected cells?

To edit a protected cell, you must first remove its protected status. You can do this using either Excel's ribbon controls or macros. The advantage in using macros is that you can change a cell's value with a single command and then leave it protected afterward.

Can you use VBA on a protected sheet?

Another option is to use VBA code like the following to protect the worksheet and it allows macros to make changes but the user cannot make changes directly on the worksheet. It is simply an example of protecting.


1 Answers

Try using

Worksheet.Protect "Password", UserInterfaceOnly := True 

If the UserInterfaceOnly parameter is set to true, VBA code can modify protected cells.

like image 65
Joe Avatar answered Sep 29 '22 17:09

Joe