我在 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 个单元格。