View Full Version : Protecting area of worksheet
I´m trying to protect an area of a worksheet with the code:
Private Sub Worksheet_Activate()
ActiveSheet.ScrollArea = "A1:A20"
End Sub
That works great.
But my problem is that i want to protect A1:A20 and C1:C15 and E15:E25 in a similar way. Can I use the above code in any way to do this? Or is there a better way to do this?
Jacob Hilderbrand
03-31-2006, 08:16 AM
You can unlock those cells and lock all the others, then change the selection to unlocked cells only.
ActiveSheet.EnableSelection = xlUnlockedCells
Thank you, I tried that in this way:
Private Sub Worksheet_Activate()
With Worksheets(1)
.EnableSelection = xlNoSelection
.Protect Contents:=True, UserInterfaceOnly:=True
End With
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
And that works. But then my next problem comes up: I would like to highligt the column and row of the active cell with the code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Cells.Interior.ColorIndex = xlNone
With ActiveCell
.EntireRow.Interior.ColorIndex = 37
.EntireColumn.Interior.ColorIndex = 37
.Interior.ColorIndex = 36
End With
End Sub
That code works well on it's own, but not togeter with the first one:(
Jacob Hilderbrand
04-04-2006, 10:47 AM
Make sure you unlock (Format | Cells | Protection) all the cells that the user can select.
I have done that, but all I get is an errorcode 1004, saying ColorIndex can't be used with class Interior. I can't understand why, because each sub works well on it's own, but not together....
Jacob Hilderbrand
04-04-2006, 04:22 PM
Try the attachment.
Thank you, that works great :thumb
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.