need code for disable selection of locked cells

D

David Lewis

Got code
Sub protect()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.EnableSelection = xlUnlockedCells
ws.protect Password:=""
Next ws

End Sub

I need to disable selection of locked cells
Is there a function like ws.DisableSelection = xlLockedCells?
 
N

Norman Jones

Hi David,
I need to disable selection of locked cells
Is there a function like ws.DisableSelection = xlLockedCells?

That is what your code does.

If, as in your code, you set the EnableSelection to unlocked cells, only
unlocked cells can be selected - locked cells become unselectable.
 
W

William

hi David

This will only allow unlocked cells to be selected as long as the sheets are
protected. You code does not unprotect the sheets first (although you could
get around this by setting the userinterface to true).

Sub test()
Dim ws As Worksheet
For Each ws In Worksheets
With ws
..Unprotect
..EnableSelection = xlUnlockedCells
..Protect
End With
Next ws
End Sub

--
XL2002
Regards

William

(e-mail address removed)

| Got code
| Sub protect()
|
| Dim ws As Worksheet
|
| For Each ws In ActiveWorkbook.Worksheets
| ws.EnableSelection = xlUnlockedCells
| ws.protect Password:=""
| Next ws
|
| End Sub
|
| I need to disable selection of locked cells
| Is there a function like ws.DisableSelection = xlLockedCells?
|
 
G

Guest

You can modify the Scroll Area to restrict which cells can be selected... It
requires a single continuious range of cells though. The user can only move
within that range of cells. Otherwise there is nothing that I know of to keep
the user from selecting a cell. Locking it only protects it from being
updated. You can hide the formula of a locked cell if that helps...

HTH
 
D

David Lewis

All I know is my code locks the page. When I save and close and go back I can select the cells again.
If I manually lock the cells and uncheck the locked cells option then it works properly.

"Norman Jones" <[email protected]>
|>Hi David,
|>
|>> I need to disable selection of locked cells
|>> Is there a function like ws.DisableSelection = xlLockedCells?
|>
|>That is what your code does.
|>
|>If, as in your code, you set the EnableSelection to unlocked cells, only
|>unlocked cells can be selected - locked cells become unselectable.
|>
|>---
|>Regards,
|>Norman
|>
|>
|>
|>|>> Got code
|>> Sub protect()
|>>
|>> Dim ws As Worksheet
|>>
|>> For Each ws In ActiveWorkbook.Worksheets
|>> ws.EnableSelection = xlUnlockedCells
|>> ws.protect Password:=""
|>> Next ws
|>>
|>> End Sub
|>>
|>> I need to disable selection of locked cells
|>> Is there a function like ws.DisableSelection = xlLockedCells?
|>>
|>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top