PDA

View Full Version : Problem with sheet protection



flowergirl
08-21-2011, 08:58 PM
Hi,

I want to make certain cells non-editable in the sheet. I am using the following code:

DestinationSheet.Cells.Locked = False
DestinationSheet.Range("N13:N52").Locked = True
DestinationSheet.Protect

But this is making the sheet protected and I cannot do further operations on the sheet. Is there a workaround?

Thanks for your help.

Aussiebear
08-21-2011, 10:33 PM
Try adding the following lineActiveSheet.EnableSelection = xlUnlockedCells

flowergirl
08-24-2011, 11:55 PM
This is not solving the problem.

Can someone please help.

Bob Phillips
08-25-2011, 12:58 AM
What other operations can you not do?

flowergirl
08-25-2011, 03:11 AM
Hi,

I have a macro defined on the sheet that pulls up some data from MS SQL Server and displays it on the sheet. That macro is not running.

That macro runs if I physically Unprotect the sheet by choosing a menu option.

If I unprotect the sheet before running the macro then the cells are no longer locked.

Please help.

Aussiebear
08-25-2011, 04:10 AM
Then may I suggest that you post your code so we can see. Else follow the logic of this layout

Sub RunMacro()

Sheet1.Unprotect Password:="Secret" ‘ß=== Change sheet name to suit

'Your Macro Code

Sheet1.Protect Password:="Secret" ‘ç=== Change sheet name to suit

End Sub

flowergirl
08-25-2011, 10:59 PM
Here's my code:

Range("B3").Select
ActiveCell.FormulaR1C1 = "9"
Cells.Select
Selection.Locked = False
Selection.FormulaHidden = False
Range("B3").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

Bob Phillips
08-26-2011, 01:36 AM
Range("B3").Value = 9
With Cells
.Locked = True
.FormulaHidden = True
End With
With Range("B3")
.Locked = False
.FormulaHidden = False
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells