Solved

Protecting Select Cells

Posted on 2014-01-30
8
171 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 45

Accepted Solution

by:
Martin Liss earned 168 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 29

Expert Comment

by:gowflow
Comment Utility
any chance to have tried out the proposed solution ?
gowflow
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Have any of the above helped you?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

15 Experts available now in Live!

Get 1:1 Help Now