在excel 2010中禁用单元格

时间:2015-06-05 20:53:17

标签: excel vba excel-vba

我的Excel工作表上有一个宏来锁定/解锁该行以进行编辑。我想阻止用户点击其他单元格,直到他锁定他正在编辑的单元格。怎么做?

我目前阻止/取消阻止单元格的代码是:

Sub Unlock_Cell()
Dim selectionAdress As String

' Set the adress of line
selectionAdress = "A" & Right(Selection.Address, 2) & ":C" & Right(Selection.Address, 2)

Worksheets("Test1").Protect Password:="qwe123@", UserInterfaceOnly:=True

With Range(selectionAdress)
    If .Cells(1).Locked Then
        .Locked = False
    Else
        .Locked = True
    End If
End With
End Sub

0 个答案:

没有答案