Excel三个下拉互斥
描述:Excel有三个下拉列表,若选择了其中任意一个下拉,其他两个均不可以在选择。
尝试了很多种办法,级联,数据有效性等等,最后都没实现。
老大,最后用VBA实现。
附上代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim n As Integer
n = 1
If Target.Column = 2 And Target.Value <> "" Then
r = Target.Row
If Range("G" & r).Value <> "" Then
MsgBox (" G 列已有内容")
Target = ""
Exit Sub
ElseIf Range("I" & r).Value <> "" Then
Target = ""
MsgBox (" I 列已有内容")
Exit Sub
End If
End If
If Target.Column = 7 And Target.Value <> "" Then
r = Target.Row
If Range("B" & r).Value <> "" Then
Target = ""
MsgBox (" B 列已有内容")
Exit Sub
ElseIf Range("I" & r).Value <> "" Then
Target = ""
MsgBox (" I 列已有内容")
Exit Sub
End If
End If
If Target.Column = 9 And Target.Value <> "" Then
r = Target.Row
If Range("G" & r).Value <> "" Then
Target = ""
MsgBox (" G 列已有内容")
Exit Sub
ElseIf Range("B" & r).Value <> "" Then
Target = ""
MsgBox (" B 列已有内容")
Exit Sub
End If
End If
End Sub