ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Cell Protection vs. Worksheet Protection (https://www.excelbanter.com/excel-discussion-misc-queries/111231-cell-protection-vs-worksheet-protection.html)

kmwhitt

Cell Protection vs. Worksheet Protection
 
Is there anyway to protect selected cells from editing without having to
protect the entire worksheet? I know that I can lock or unlock certain cells
when I protect the worksheet as a whole, but when I use worksheet protection,
it interferes with some of my code and user functionality.... Please
advise...

Thanks,

Kevin

Ken Johnson

Cell Protection vs. Worksheet Protection
 

kmwhitt wrote:
Is there anyway to protect selected cells from editing without having to
protect the entire worksheet? I know that I can lock or unlock certain cells
when I protect the worksheet as a whole, but when I use worksheet protection,
it interferes with some of my code and user functionality.... Please
advise...

Thanks,

Kevin


Hi Kevin,

Change your code so that it unprotects the sheet, makes its changes,
then protects the sheet.

Eg...

Public Sub CodeForProtection()
With Sheet1
..Unprotect "ken"
..Range("A1").Value = 1
..Protect "ken"
End With
End Sub

If you are not using a password then you just use .Unprotect and
..Protect on their own.

Ken Johnson


kassie

Cell Protection vs. Worksheet Protection
 
That's the only way! However, macros can also unprotect and reprotect your
worksheet.

"kmwhitt" wrote:

Is there anyway to protect selected cells from editing without having to
protect the entire worksheet? I know that I can lock or unlock certain cells
when I protect the worksheet as a whole, but when I use worksheet protection,
it interferes with some of my code and user functionality.... Please
advise...

Thanks,

Kevin


Dave Peterson

Cell Protection vs. Worksheet Protection
 
Depending on what your code does, you can protect the worksheet in code.

Option Explicit
Sub auto_open()
With Worksheets("sheet1")
.Protect Password:="hi", userinterfaceonly:=True
End With
End Sub

The userinterfaceonly means that you're stopping the user from changing locked
cells on a protected worksheet (Sheet1, in my example). But your code can
change things that the user can't.

But do some testing. There are a few things that still need you to unprotect
the worksheet, do your stuff, and protect the worksheet. (But maybe you're not
doing one of those few things.)

kmwhitt wrote:

Is there anyway to protect selected cells from editing without having to
protect the entire worksheet? I know that I can lock or unlock certain cells
when I protect the worksheet as a whole, but when I use worksheet protection,
it interferes with some of my code and user functionality.... Please
advise...

Thanks,

Kevin


--

Dave Peterson

kmwhitt

Cell Protection vs. Worksheet Protection
 
Thanks for all your help, guys!

"kmwhitt" wrote:

Is there anyway to protect selected cells from editing without having to
protect the entire worksheet? I know that I can lock or unlock certain cells
when I protect the worksheet as a whole, but when I use worksheet protection,
it interferes with some of my code and user functionality.... Please
advise...

Thanks,

Kevin



All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com