Excel VBA宏-Pt2

问题描述 投票:1回答:1

试图限制用户从具有条件格式列表]的3列中选择任何内容>

目标范围:(三列L:N),即L3,M3,N3至L40,M40,N40。

除非用户首先在U列中填充字段,否则>

目标范围:U3-U40

我已经尝试搜索如何锁定单元格的选择,除非在最近几天没有选择相应的单元格,否则无济于事。认为问题在于,因为目标单元格实际上没有输入值,而是使用条件格式的列表。

谢谢!安德鲁。

[试图限制用户从具有条件格式列表的3列中选择任何内容。目标范围:(三列L:N),即L3,M3,N3到L40,M40,N40。除非用户先...

excel vba conditional-formatting
1个回答
0
投票

在您要保护的工作表的代码模块中,请输入以下内容...

Private Sub Worksheet_Activate()
    Shield
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    Shield
    If Len(Me.[u5]) Then Me.Unprotect '<-- change 'u5' to the cell in column U that unlocks
End Sub

Sub Shield()
    With Me
        .Unprotect
        .Cells.Locked = False
        .[L3:n40].Locked = True
        .Protect , 0, 1, 0, 1, 1, 1, 1, 1, 1, 1
    End With
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.