View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Lock and protect ranges



Since your original post said TEXT, I wrote this for that to NOT lock
numbers. If you want to lock ALL cells that are not blanks, simply remove
the

,2

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Sub IfTextLock()
With ActiveSheet
.Unprotect
.Columns(1).SpecialCells _
(xlCellTypeConstants, 2).EntireRow.Locked = True
.Protect
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"simon" wrote in message
...
I've adapted some code I found on this group to protect rows that have
text in column A. Here is the code which runs on the Save event:
Dim i As Integer
ActiveSheet.Unprotect
For i = 1 To Range("A65536").End(xlUp).Row
If Cells(i, 1).Value < "" Then
Cells(i, 1).EntireRow.Locked = True
Else
Cells(i, 1).EntireRow.Locked = False
End If
Next i
ActiveSheet.Protect

Interestingly I discovered that when I only had one row of information
not only was that row protected but also all the rows below it.
However when I inserted an additional row both rows with text in
column A were protected but other rows could be edited as originally
intended.

Can anyone explain why this is happening. It took me some while to
fathom.

Many thanks in anticipation

Simon