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.
If the UserInterfaceOnly parameter is set to true, VBA code can modify protected cells. This is a better solution, of course.
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.
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.
Try using
Worksheet.Protect "Password", UserInterfaceOnly := True
If the UserInterfaceOnly parameter is set to true, VBA code can modify protected cells.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With