代码
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandlerOn Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then'do nothing
ElseApplication.EnableEvents = FalsenewVal = Target.ValueApplication.UndooldVal = Target.ValueTarget.Value = newVal//在第几列写几If Target.Column = 5 ThenIf oldVal = "" ThenElseIf newVal = "" ThenElseIf InStr(oldVal, newVal) > 0 ThenTarget.Value = oldValElseTarget.Value = oldVal & ", " & newValEnd IfEnd IfEnd IfEnd If
End IfexitHandler:
Application.EnableEvents = True
End Sub
设置单选数据