如果没有背景颜色,我正在尝试解锁给定范围内的单元格。
Sub macunlock()
Dim rng1 As Range
Set rng1 = Range("A1:C1")
For Each cell In rng1
If cell.Interior.ColorIndex = 0 Then cell.Locked = False
Next cell
End Sub
但是,指定的单元格无法解锁。
答案 0 :(得分:2)
因为,空白格式为-4142
而非0
更改为:
If cell.Interior.ColorIndex = -4142 Then cell.Locked = False
健全的方式:
Sub macunlock()
Dim rng1 As Range
Set rng1 = Range("A1:C1")
For Each cell In rng1
If cell.Interior.ColorIndex = XlColorIndex.xlColorIndexNone Then
cell.Locked = False
End If
Next cell
End Sub