gracepinas
01-11-2009, 07:02 PM
i am looking for a code that will help me determine which of the cells have colored then lock the cells
i found one in this forum
but why i am having an error on the line below colored in red
Sub UnprotectGreenCells()
' Macro purpose: To unlock all green cells
' NOTE: All worksheets in the workbook must be
' Unprotected before this procedure is run
Dim cl As Range, ws As Worksheet, lColor As Long
' Set the cell color that you want to protect
lColor = 35 'green
' It may be a good idea to test all sheets to see if any are protected
' here. One method to do this would be to test the function found here
' Cycle through each worksheet in the workbook
For Each ws In ActiveWorkbook.Worksheets
For Each cl In ws.UsedRange
' Change colored cell to unlocked, and all other cells to locked
If cl.Interior.ColorIndex = lColor Then
cl.Locked = False
Else
If cl.MergeCells = True Then
cl.MergeArea.Locked = True
Else
cl.Locked = True
End If
End If
Next cl
Next ws
End Sub
i found one in this forum
but why i am having an error on the line below colored in red
Sub UnprotectGreenCells()
' Macro purpose: To unlock all green cells
' NOTE: All worksheets in the workbook must be
' Unprotected before this procedure is run
Dim cl As Range, ws As Worksheet, lColor As Long
' Set the cell color that you want to protect
lColor = 35 'green
' It may be a good idea to test all sheets to see if any are protected
' here. One method to do this would be to test the function found here
' Cycle through each worksheet in the workbook
For Each ws In ActiveWorkbook.Worksheets
For Each cl In ws.UsedRange
' Change colored cell to unlocked, and all other cells to locked
If cl.Interior.ColorIndex = lColor Then
cl.Locked = False
Else
If cl.MergeCells = True Then
cl.MergeArea.Locked = True
Else
cl.Locked = True
End If
End If
Next cl
Next ws
End Sub