Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default lock all cells of a certain color

Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default lock all cells of a certain color


TxRaistlin wrote:
Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason


Hi Jason,

Change the two False values to True. False Unlocks and UnHides.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default lock all cells of a certain color

Sub lock_all_tan()

Dim s as Worksheet, c as Range
For Each s In WorkSheets
s.Activate
s.Unprotect Password:="ABC"
For Each c In s.UsedRange.Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next


You will need to then protect the sheet for it to have any effect
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default lock all cells of a certain color

Also, Locking is only effective after Protection is applied.

Ken Johnson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default lock all cells of a certain color

I received the following error:

Object doesn't support this property.

I made a mistake in my original description, I am wanting to unlock only
those cells that are tan, everything else stays locked.

Thanks,

Jason


"Tom Ogilvy" wrote:

Sub lock_all_tan()

Dim s as Worksheet, c as Range
For Each s In WorkSheets
s.Activate
s.Unprotect Password:="ABC"
For Each c In s.UsedRange.Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next


You will need to then protect the sheet for it to have any effect
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default lock all cells of a certain color

If you are using conditional formatting to color the cells,
then none of the code will work. If you are not using CF then
in Tom's code change...

If c.ColorIndex = 40 Then

to

If c.Interior.ColorIndex = 40 Then
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"TxRaistlin"

wrote in message
I received the following error:
Object doesn't support this property.

I made a mistake in my original description, I am wanting to unlock only
those cells that are tan, everything else stays locked.
Thanks,
Jason


"Tom Ogilvy" wrote:
Sub lock_all_tan()
Dim s as Worksheet, c as Range
For Each s In WorkSheets
s.Activate
s.Unprotect Password:="ABC"
For Each c In s.UsedRange.Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next


You will need to then protect the sheet for it to have any effect
End Sub
--
Regards,
Tom Ogilvy


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default lock all cells of a certain color

Sub unlock_all_tan()

Dim s As Worksheet, c As Range
For Each s In Worksheets
s.Activate
s.Unprotect Password:="ABC"
s.Cells.Locked = True
s.Cells.formulaHidden = True
For Each c In s.UsedRange.Cells
If c.Interior.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

I received the following error:

Object doesn't support this property.

I made a mistake in my original description, I am wanting to unlock only
those cells that are tan, everything else stays locked.

Thanks,

Jason


"Tom Ogilvy" wrote:

Sub lock_all_tan()

Dim s as Worksheet, c as Range
For Each s In WorkSheets
s.Activate
s.Unprotect Password:="ABC"
For Each c In s.UsedRange.Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next


You will need to then protect the sheet for it to have any effect
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default lock all cells of a certain color

Thanks!

"Tom Ogilvy" wrote:

Sub unlock_all_tan()

Dim s As Worksheet, c As Range
For Each s In Worksheets
s.Activate
s.Unprotect Password:="ABC"
s.Cells.Locked = True
s.Cells.formulaHidden = True
For Each c In s.UsedRange.Cells
If c.Interior.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

I received the following error:

Object doesn't support this property.

I made a mistake in my original description, I am wanting to unlock only
those cells that are tan, everything else stays locked.

Thanks,

Jason


"Tom Ogilvy" wrote:

Sub lock_all_tan()

Dim s as Worksheet, c as Range
For Each s In WorkSheets
s.Activate
s.Unprotect Password:="ABC"
For Each c In s.UsedRange.Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
s.Protect Password:="ABC"
Next


You will need to then protect the sheet for it to have any effect
End Sub

--
Regards,
Tom Ogilvy


"TxRaistlin" wrote:

Haven't found this yet in previous threads, but I'm sure i missed it.

I am trying to Lock all cells that are a certain color as follows:

Sub lock_all_tan()

For Each s In Sheets
For Each c In Cells
If c.ColorIndex = 40 Then
c.Locked = False
c.FormulaHidden = False
End If
Next
Next

End Sub

The above doesn't work at all, appreciate any help. Thanks, Jason

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
How do I lock the color palette? Venus Excel Discussion (Misc queries) 3 February 24th 09 11:53 PM
How do I lock the color palette? Venus Excel Discussion (Misc queries) 5 February 24th 09 11:52 PM
How do I lock the color palette? Venus Excel Discussion (Misc queries) 0 February 13th 09 07:47 PM
how do I lock the fill color in a cell Graham Excel Worksheet Functions 4 February 9th 09 05:46 PM
lock cells based on interior color MIke Excel Discussion (Misc queries) 4 December 27th 07 08:59 PM


All times are GMT +1. The time now is 04:14 PM.

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"