Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Locking and Unlocking Cells via VBA

Dear Experts:
I would like to achieve the following on the ACTIVE workseet by
applying a VBA code:

1. Lock all the cells of the current worksheet that would be selected
by pressing Ctrl+Shift+End
2. De-lock those cells that require data entries by the user, i.e
cells where data entry is restricted to certain values (by data
validation)

Help is much appreciated.

Thank you very much in advance.

Regards, Andreas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Locking and Unlocking Cells via VBA

Try this one out and post back what needs to be changed if anything:

Sub DoTheLock()

Const MyPWD As String = "TypeYourPWDHere"

With ActiveSheet
'unprotect you ws
.Unprotect MyPWD
'lock used range
.UsedRange.Locked = True
On Error GoTo ThereAreNoValidations:
'unlock celsl with validation
.Cells.SpecialCells(xlCellTypeAllValidation).Locke d =
False
On Error GoTo 0
'Re-protect the ws
.Protect MyPWD
End With

ExitSub:
On Error GoTo 0
Exit Sub

ThereAreNoValidations:
MsgBox "No cell has a validation!", vbExclamation

End Sub


On Feb 3, 6:45*am, andreashermle wrote:
Dear Experts:
I would like to achieve the following on the ACTIVE workseet by
applying a VBA code:

1. Lock all the cells of the current worksheet that would be selected
by pressing Ctrl+Shift+End
2. De-lock those cells that require data entries by the user, i.e
cells where data entry is restricted to certain values (by data
validation)

Help is much appreciated.

Thank you very much in advance.

Regards, Andreas


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Locking and Unlocking Cells via VBA

On 3 Feb., 10:52, AB wrote:
Try this one out and post back what needs to be changed if anything:

Sub DoTheLock()

* * Const MyPWD As String = "TypeYourPWDHere"

* * With ActiveSheet
* * * * 'unprotect you ws
* * * * .Unprotect MyPWD
* * * * 'lock used range
* * * * .UsedRange.Locked = True
* * * * On Error GoTo ThereAreNoValidations:
* * * * * * 'unlock celsl with validation
* * * * * * .Cells.SpecialCells(xlCellTypeAllValidation).Locke d =
False
* * * * On Error GoTo 0
* * * * 'Re-protect the ws
* * * * .Protect MyPWD
* * End With

ExitSub:
* * On Error GoTo 0
* * Exit Sub

ThereAreNoValidations:
* * MsgBox "No cell has a validation!", vbExclamation

End Sub

On Feb 3, 6:45*am, andreashermle wrote:

Dear Experts:
I would like to achieve the following on the ACTIVE workseet by
applying a VBA code:


1. Lock all the cells of the current worksheet that would be selected
by pressing Ctrl+Shift+End
2. De-lock those cells that require data entries by the user, i.e
cells where data entry is restricted to certain values (by data
validation)


Help is much appreciated.


Thank you very much in advance.


Regards, Andreas


Dear AB:

works like a charm. Exactly what I wanted. Thank you very much for
your superb help.

Regards, Andreas
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Locking and Unlocking Cells via VBA

No worries - thanks for the feedback!

A.

On Feb 4, 2:37*pm, andreashermle wrote:
On 3 Feb., 10:52, AB wrote:





Try this one out and post back what needs to be changed if anything:


Sub DoTheLock()


* * Const MyPWD As String = "TypeYourPWDHere"


* * With ActiveSheet
* * * * 'unprotect you ws
* * * * .Unprotect MyPWD
* * * * 'lock used range
* * * * .UsedRange.Locked = True
* * * * On Error GoTo ThereAreNoValidations:
* * * * * * 'unlock celsl with validation
* * * * * * .Cells.SpecialCells(xlCellTypeAllValidation).Locke d =
False
* * * * On Error GoTo 0
* * * * 'Re-protect the ws
* * * * .Protect MyPWD
* * End With


ExitSub:
* * On Error GoTo 0
* * Exit Sub


ThereAreNoValidations:
* * MsgBox "No cell has a validation!", vbExclamation


End Sub


On Feb 3, 6:45*am, andreashermle wrote:


Dear Experts:
I would like to achieve the following on the ACTIVE workseet by
applying a VBA code:


1. Lock all the cells of the current worksheet that would be selected
by pressing Ctrl+Shift+End
2. De-lock those cells that require data entries by the user, i.e
cells where data entry is restricted to certain values (by data
validation)


Help is much appreciated.


Thank you very much in advance.


Regards, Andreas


Dear AB:

works like a charm. Exactly what I wanted. Thank you very much for
your superb help.

Regards, Andreas- Hide quoted text -

- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking/unlocking cells based on column headers Hugo Excel Programming 5 July 29th 09 09:25 PM
Unlocking and Locking in a Marco JBoyer Excel Programming 3 July 12th 08 03:36 AM
locking and unlocking worksheets adam Excel Worksheet Functions 6 October 31st 07 05:31 PM
Locking/Unlocking cells upon condition Brettjg Excel Discussion (Misc queries) 20 March 12th 07 06:01 AM
Locking/unlocking cells Ian Coates Excel Programming 1 February 3rd 04 04:04 PM


All times are GMT +1. The time now is 02:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"