Solved

Protecting Select Cells

Posted on 2014-01-30
8
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 48

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 31

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 31

Expert Comment

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

Expert Comment

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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

632 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