Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Protect Cells

All of the Cells in the Range("C40:K40,M40:U40") are unlocked, however as a
result of the following code only those cells which have the validation
added need to be unlocked. The rest can be locked.
My question - Is it possible to only unlock the cells with validation added
at runtime.

For Each mycell In Range("")
'***The following can be locked
If mycell.Value = "Hit" Then
With mycell.Offset(1)
.Validation.Delete
.Value = ""
End With
'***The following Must be unlocked
ElseIf mycell.Value = "Miss" Then
With mycell.Offset(1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="Right,Wrong"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
Next

Sandy


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Protect Cells

Untested but I think this is what you are looking for...

Sub LockCells()
Dim rngValidation As Range

Cells.Locked = False
On Error Resume Next
Set rngValidation = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

If Not rngValidation Is Nothing Then rngValidation.Locked = False
End Sub
--
HTH...

Jim Thomlinson


"Sandy" wrote:

All of the Cells in the Range("C40:K40,M40:U40") are unlocked, however as a
result of the following code only those cells which have the validation
added need to be unlocked. The rest can be locked.
My question - Is it possible to only unlock the cells with validation added
at runtime.

For Each mycell In Range("")
'***The following can be locked
If mycell.Value = "Hit" Then
With mycell.Offset(1)
.Validation.Delete
.Value = ""
End With
'***The following Must be unlocked
ElseIf mycell.Value = "Miss" Then
With mycell.Offset(1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="Right,Wrong"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
Next

Sandy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Protect Cells

Didn't get the chance to try it either - but I will report back.
Sandy

"Jim Thomlinson" wrote in message
...
Untested but I think this is what you are looking for...

Sub LockCells()
Dim rngValidation As Range

Cells.Locked = False
On Error Resume Next
Set rngValidation = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

If Not rngValidation Is Nothing Then rngValidation.Locked = False
End Sub
--
HTH...

Jim Thomlinson


"Sandy" wrote:

All of the Cells in the Range("C40:K40,M40:U40") are unlocked, however as
a
result of the following code only those cells which have the validation
added need to be unlocked. The rest can be locked.
My question - Is it possible to only unlock the cells with validation
added
at runtime.

For Each mycell In Range("")
'***The following can be locked
If mycell.Value = "Hit" Then
With mycell.Offset(1)
.Validation.Delete
.Value = ""
End With
'***The following Must be unlocked
ElseIf mycell.Value = "Miss" Then
With mycell.Offset(1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="Right,Wrong"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
Next

Sandy





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Protect Cells

Hi Jim
With the following adjustments it works beatifully:-

Dim rngValidation As Range
Dim rngPossibleValidation As Range

Set rngPossibleValidation =
Range("C14:K14,M14:U14,C15:K15,M15:U15,--Etc--,M23:U23")
rngPossibleValidation.Cells.Locked = True

'On Error Resume Next

Set rngValidation = Cells.SpecialCells(xlCellTypeAllValidation)
rngValidation.Cells.Locked = False

'On Error GoTo 0

'If Not rngValidation Is Nothing Then rngValidation.Locked = False

I have commented out (as you can see) the 'On Error' lines and the 'If Not
rngValidation Etc' - are they really needed?
Sandy

"Jim Thomlinson" wrote in message
...
Untested but I think this is what you are looking for...

Sub LockCells()
Dim rngValidation As Range

Cells.Locked = False
On Error Resume Next
Set rngValidation = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo 0

If Not rngValidation Is Nothing Then rngValidation.Locked = False
End Sub
--
HTH...

Jim Thomlinson


"Sandy" wrote:

All of the Cells in the Range("C40:K40,M40:U40") are unlocked, however as
a
result of the following code only those cells which have the validation
added need to be unlocked. The rest can be locked.
My question - Is it possible to only unlock the cells with validation
added
at runtime.

For Each mycell In Range("")
'***The following can be locked
If mycell.Value = "Hit" Then
With mycell.Offset(1)
.Validation.Delete
.Value = ""
End With
'***The following Must be unlocked
ElseIf mycell.Value = "Miss" Then
With mycell.Offset(1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="Right,Wrong"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
Next

Sandy





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
protect cells in excel, but also allow a search in those cells? LindaAlex Excel Worksheet Functions 2 January 28th 10 02:51 PM
How do I protect cells or a range of cells in excel spreadsheet? Abundance Excel Worksheet Functions 1 July 28th 09 11:03 PM
Protect Cells ??? Jcraig713 Excel Discussion (Misc queries) 2 January 27th 06 02:57 PM
protect cells Anthony Excel Discussion (Misc queries) 3 November 21st 05 03:12 PM
Lock and protect cells without protect the sheet Christian[_7_] Excel Programming 6 December 28th 04 04:50 PM


All times are GMT +1. The time now is 03:55 AM.

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

About Us

"It's about Microsoft Excel"