Excel表格中有2列。 A1
包含一个下拉列表,其值为“启用”和“禁用”。需要根据A1
下拉选项启用或禁用单元B1和C1。
我尝试使用数据验证,但它不起作用。任何人都可以建议我如何使用数据验证来实现这一目标吗?
A | B
------------------------
1 Suggestions| (This cell should disable (B1))
------------------------
2 Errors| (Now here drop down will come with values(B2))
------------------------
当前VBA
Private Sub Worksheet_Change(ByVal Target As Range)
ThisRow = Target.Row
If Target = Range("A1") Then
If Target.Value = "Suggestions" Then
Worksheets("Code Review").Range("B:C").Locked = True
End If
Else
Worksheets("Code Review").Range("B:C").Locked = False
End If
End Sub
也尝试过这样
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
If Not Intersect(Range("A:A"), Target) Is Nothing Then
Application.EnableEvents = False
Me.Unprotect
For Each cel In Intersect(Range("A:A"), Target)
cel.Offset(ColumnOffset:=1).Resize(ColumnSize:=2).Locked = _
cel.Value = "Suggestion"
Next cel
Me.Protect
Application.EnableEvents = True
End If
但这锁定了一切:(我只想锁定2个细胞。