I have found following code to cell protect by color. It only work for activesheet. Can we expand for active workbook?
Sub Lock_Color()
Dim colorIndex As Integer
Dim Range As Range
'Lock all the cells that are selected color
colorIndex = 6 '6 = yellow
For Each Range In ActiveSheet.UsedRange.Cells
Dim color As Long
color = Range.Interior.colorIndex
If (color = colorIndex) Then
Range.Locked = True
Else
Range.Locked = False
End If
Next Range
'Protect worksheet
ActiveSheet.Protect Password:="123456", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
MsgBox "Highlighted cells are locked!"
End Sub
Sub Lock_Color()
Dim colorIndex As Integer
Dim Range As Range
'Lock all the cells that are selected color
colorIndex = 6 '6 = yellow
For Each Range In ActiveSheet.UsedRange.Cells
Dim color As Long
color = Range.Interior.colorIndex
If (color = colorIndex) Then
Range.Locked = True
Else
Range.Locked = False
End If
Next Range
'Protect worksheet
ActiveSheet.Protect Password:="123456", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
MsgBox "Highlighted cells are locked!"
End Sub