-
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?
-
You can unlock those cells and lock all the others, then change the selection to unlocked cells only.
[VBA]ActiveSheet.EnableSelection = xlUnlockedCells[/VBA]
-
Thank you, I tried that in this way:
[VBA]
Private Sub Worksheet_Activate()
With Worksheets(1)
.EnableSelection = xlNoSelection
.Protect Contents:=True, UserInterfaceOnly:=True
End With
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
[/VBA]
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:
[VBA]
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
[/VBA]
That code works well on it's own, but not togeter with the first one
-
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....
-
-
Thank you, that works great
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules