Solved

Protecting Select Cells

Posted on 2014-01-30
8
194 Views
Last Modified: 2014-03-06
Hi All,

I have a workbook, in which I need to protect a few specific cells. When I tried locking it through the protect sheet/workbook option, it kills the vba which powers other functions.

I tried using the following code..

Sheets("Sheet1").UnProtect Password:="MyPassword"
...
Your code
...
Sheets("Sam").Protect Password:="MyPassword"

But unfortunately, I think I placed the code in the wrong area.

I need to protect:c2, c11:c138, e11:138

**The VBA project is password protect but its blank just hit ok.

Thanks,
test-1-30-14.xlsm
0
Comment
Question by:J_Drake
  • 3
  • 2
8 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 168 total points
ID: 39822193
Try protecting this way instead.

        Worksheets("Sam").Protect Password:="Password", Userinterfaceonly:=True, DrawingObjects:=False
0
 
LVL 29

Assisted Solution

by:gowflow
gowflow earned 166 total points
ID: 39822238
First of all you refer to
Sheets("Sam").Protect Password

and you don't have a sheet called Sam

then
what sheet you want to protect
c2, c11:c138, e11:138
I assume it is sheet Action Register.

If it is the case then you should think differently and decide what are the cells you want to Unlock !! as by default the whole worksheet is locked when you protect a worksheet reason why your code is bugging as it is hitting a locked cell that you are maybe changing by code and if the sheet is locked then it blocks.

I suggest the following:

1) You just unlock all the cells that you want the user to have access to and this point to the cell or group of cells and hit right click format cell protection and untick Locked.

2) In all the code that access this sheet (I did not go thru the code but if you want me to just lead me to what are the routines that affect this sheet)

3) so in all these routines you should have in the beging of the routine
sheets("Action Register").Unprotect Password:="MyPassword"
...
your code for the routine
and at the end
sheets("Action Register").protect Password:="MyPassword"

this way when the code runs it will run with unlocked sheet and make changes freely.

4) You need to make sure that in your Workbook_Open event you have:
sheets("Action Register").protect Password:="MyPassword"
so it Protect the worksheet upon opening the workbook.

Pls let me know if you need specific attendance on this code and where.
gowflow
0
 
LVL 22

Assisted Solution

by:spattewar
spattewar earned 166 total points
ID: 39822295
Please note that if you are using MartinLiss's solution you need to make sure that you put it in the workbook open event. Because the userinterface protection does not get saved when you save the workbook.

This is the best way to do it if you want the VBA code to do its stuff but prevent manual input on the sheet.

Hope it helps.
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 29

Expert Comment

by:gowflow
ID: 39827998
any chance to have tried out the proposed solution ?
gowflow
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39842746
Have any of the above helped you?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39908811
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question