Skip to content

Instantly share code, notes, and snippets.

@dsbraz
Created April 25, 2015 02:11
Show Gist options
  • Save dsbraz/8a35fd5589c00ee9fc54 to your computer and use it in GitHub Desktop.
Save dsbraz/8a35fd5589c00ee9fc54 to your computer and use it in GitHub Desktop.
Multiselect dropdown no Excel
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 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
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
Else
If newVal = "" Then
Else
If oldVal = newVal Then
Target.Value = ""
Else
If InStr(oldVal, newVal & ",") Then
Target.Value = Replace(oldVal, newVal & ",", "")
Else
If InStr(oldVal, "," & newVal) Then
Target.Value = Replace(oldVal, "," & newVal, "")
Else
Target.Value = oldVal & "," & newVal
End If
End If
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment