ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   need code for disable selection of locked cells (https://www.excelbanter.com/excel-programming/320258-need-code-disable-selection-locked-cells.html)

David Lewis[_3_]

need code for disable selection of locked cells
 
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?


Norman Jones

need code for disable selection of locked cells
 
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



"David Lewis" wrote in message
...
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?




William[_2_]

need code for disable selection of locked cells
 
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



"David Lewis" wrote in message
...
| 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?
|



Jim Thomlinson[_3_]

need code for disable selection of locked cells
 
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

"David Lewis" wrote:

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?



David Lewis[_3_]

need code for disable selection of locked cells
 
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"
|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
|
|
|
|"David Lewis" wrote in message
. ..
| 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?
|
|



All times are GMT +1. The time now is 06:27 PM.

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