将数值input到数据validation单元格时,如何避免重复,从而允许进行多重select

在我的数据库中有一些列,这需要我input新的数据以及做出select。 所以,我通过数据validation做了一个下拉列表。 我可以根据代码select多个选项,但是如果我将任何数据键入该单元格,原始select将显示两次。

例如。 单元格包含选项:ABC,XYZ
我select了ABC,inputWWW
细胞将显示ABC,ABC,WWW

任何人都可以帮助防止重复的原始select?

这里是我现在的代码,我试图删除“oldVal”部分,以防止重复,它阻止我select多个select。

Private Sub Worksheet_Change(ByVal Target As Range) Dim rngDV As Range Dim oldVal As String Dim newVal As String Dim lUsed As Long If Target.Count > 1 Then GoTo exitHandler On 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 Else Application.EnableEvents = False newVal = Target.Value Application.Undo oldVal = Target.Value Target.Value = newVal If Target.Column = 28 Or Target.Column = 29 Or Target.Column = 30 Then If oldVal = "" Then 'do nothing Else If newVal = "" Then 'do nothing Else lUsed = InStr(1, oldVal, newVal) If lUsed > 0 Then If oldVal = newVal Then Target.Value = "" ElseIf Right(oldVal, Len(newVal)) = newVal Then Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 1) Else Target.Value = Replace(oldVal, newVal & vbLf, "") End If Else Target.Value = oldVal & vbLf & newVal End If End If End If End If End If exitHandler: Application.EnableEvents = True End Sub