Solved

Protecting Select Cells

Posted on 2014-01-30
8
184 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now