HI EXCEL COMMUNITY! I would like to be able to select multiple items from a list. In the attached file, I have my list, cells A3-A6. In cell C2 I have the option to select from a list. I would like cell C2 to show like cell F3. I would also like it to be available to the entire workbook. I have this programed so far in the VBA of the Workbook for columns 3 & 4, see below. However, the output isn't giving me the results I desire. Am I writing the VBA code incorrectly?
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Column = 3 Or Target.Column = 4 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 & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
Bookmarks