I needed the option to select multiple items from a dropdown list in 2 different columns, and found code that works great (How to Make Multiple Selections in an Excel Drop-Down List –)
However, I also need the ability to delete selections later, but I keep getting an error saying the deletion doesn't match my list table items.
For example: if I select - Item 1, Item 2 Item 3, Item 4. Then at a later date, I might need to remove Item 3 from the list. Is there a way to delete Item 3 without having to clear the cell data and reentering only the valid Items?
My list for the dropdown menu is on a sperate worksheet (if that matters)
Here is the code I'm using:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("E3:E163,H3:H163")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & vbNewLine & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
However, I also need the ability to delete selections later, but I keep getting an error saying the deletion doesn't match my list table items.
For example: if I select - Item 1, Item 2 Item 3, Item 4. Then at a later date, I might need to remove Item 3 from the list. Is there a way to delete Item 3 without having to clear the cell data and reentering only the valid Items?
My list for the dropdown menu is on a sperate worksheet (if that matters)
Here is the code I'm using:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Not Intersect(Target, Range("E3:E163,H3:H163")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & vbNewLine & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub