View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Stuart[_5_] Stuart[_5_] is offline
external usenet poster
 
Posts: 413
Default Code to colour Unlocked cells

Many thanks to you both. I see what you mean.
One further question please:

When individual cells are coloured it's not so bad that Excel's
default gridlines are obliterated.........but when a large portion
of the screen is coloured, it's difficult to orientate without
those gridlines.

How do I get the gridlines back for the cells that change colour
.....or, would it be quicker to set the gridlines for the usedrange
once the colour-changing is complete?

Regards.

"Bob Phillips" wrote in message
...
Stuart,

You are processing the columns, not the cells. Try this

Sub Test_Protection()
Dim ws As Worksheet, c As Range
Dim cell As Range
For Each ws In ActiveWorkbook.Worksheets
With ws
.Unprotect
For Each c In .UsedRange.Columns("A:G")
For Each cell In c.Cells
With cell
If Not cell.Locked = True Then
'User is permitted to edit this cell, so color it:
cell.Interior.ColorIndex = 34
End If
End With
Next cell
Next c
End With
Next
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Stuart" wrote in message
...
I create a workbook with just one sheet, and make sure that
range("A1") is not Locked. With this book as the activeworkbook,
I run this code:

Sub Test_Protection()
Dim ws As Worksheet, c As Range
For Each ws In ActiveWorkbook.Worksheets
With ws
.Unprotect
For Each c In .UsedRange.Columns("A:G")
With c
If Not c.Locked = True Then
'User is permitted to edit this cell, so color it:
c.Interior.ColorIndex = 34
End If
If Not .Range("A1").Locked = True Then
.Range("A1").Interior.ColorIndex = 34
End If
End With
Next
End With
Next
End Sub

In this example, the 'c' code does not recognise that "A1" is
not Locked, but the "A1" code does, and the cell is coloured
correctly.

Why is the line 'If Not c.Locked = True Then' failing please?

Regards.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.692 / Virus Database: 453 - Release Date: 28/05/2004