锁定空单元格并解锁空闲单元格

时间:2017-04-20 06:26:29

标签: excel vba excel-vba

Error Message我是Excel新手,我正在尝试编写锁定空单元格的代码并解锁带有值的单元格,任何帮助都将受到高度赞赏。这就是我所拥有的,它给了我

  

运行时错误' 1004':方法'对象范围' _Global'失败。

Sub test()
    Dim rngTemp As Range

    For Each rngTemp In Range("grey").Cells
        With rngTemp
            If .Value > 0 Or Len(.Value) > 0 Then
                .Locked = False
            End If
        End With
    Next
End Sub

1 个答案:

答案 0 :(得分:2)

您的代码适用于我。你确定你有一个名为“灰色”的范围吗? Your code works fine for me. Are you sure you have a range called "grey"?