Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Code to colour Unlocked cells

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Code to colour Unlocked cells

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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to colour Unlocked cells

It appears that when you specify the columns in the .UsedRange property
it returns the entire used range in the column to your c variable.
Then the checking for locked will not work (since the entire range i
not locked). You will need to specify your range in a different manor
Something like:

Dim BigRange as Range
Set BigRange = Range("A1:G" & Range("G65536").End(xlUp).Row




--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Code to colour Unlocked cells

Don't know if this would help, but in later versions of Excel, the following
appears to work... without a loop.

Sub Demo()
Application.FindFormat.Locked = False
Application.ReplaceFormat.Interior.ColorIndex = 4
Columns("A:G").Replace _
What:=vbNullString, _
Replacement:=vbNullString, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=True, _
ReplaceFormat:=True

End Sub

HTH :)
Dana DeLouis


"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




  #5   Report Post  
Posted to microsoft.public.excel.programming
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code to colour Unlocked cells

You have to use borders.

--
Regards,
Tom Ogilvy

"Stuart" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Code to colour Unlocked cells

Many thanks but it would appear not for me!
Using Excel 2000 and Win2k.

I get this error on the line:
Application.FindFormat.Locked = False

Run time error 438
Object doesn't support this property or method

I had begun to wonder if I could use the statement
.EnableSelection = xlUnlockedCells
in some way, since this seems to indicate a way to
'globally' identify the unlocked cells, rather than a
cell by cell approach.

Regards.

"Dana DeLouis" wrote in message
...
Don't know if this would help, but in later versions of Excel, the

following
appears to work... without a loop.

Sub Demo()
Application.FindFormat.Locked = False
Application.ReplaceFormat.Interior.ColorIndex = 4
Columns("A:G").Replace _
What:=vbNullString, _
Replacement:=vbNullString, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=True, _
ReplaceFormat:=True

End Sub

HTH :)
Dana DeLouis


"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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 413
Default Code to colour Unlocked cells

Thanks and Regards.

"Tom Ogilvy" wrote in message
...
You have to use borders.

--
Regards,
Tom Ogilvy

"Stuart" wrote in message
...
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






---
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


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
VBA code to automatically colour cells depending on text? mj_bowen Excel Discussion (Misc queries) 0 January 2nd 10 07:44 PM
How to change font colour in unlocked cell of protected sheet Michelle Excel Discussion (Misc queries) 2 September 16th 08 05:58 PM
paste locked cells and unlocked cells in protected sheet Angeline Excel Worksheet Functions 15 November 1st 06 11:51 PM
Moving from unlocked cells to unlocked cells in an excel form Stacey Lee Excel Worksheet Functions 1 April 24th 06 08:44 PM
Tabbing through Unlocked cells Susan Excel Worksheet Functions 0 March 26th 06 11:51 PM


All times are GMT +1. The time now is 03:08 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"