Created
April 25, 2015 02:11
-
-
Save dsbraz/8a35fd5589c00ee9fc54 to your computer and use it in GitHub Desktop.
Multiselect dropdown no Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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