Hi,
Could someone assist me in modifying the code below so that it uses a line break instead of a comma delimited, I want to insert this into different cells, not just one specific one.
[/CODE]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) ' Edited to allow deselection of item (courtesy of Jamie Counsell) Application.EnableEvents = True On Error GoTo Exitsub If Target.Address = "$A$14" Then If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then GoTo Exitsub ElseIf Target.Value = "" Then GoTo Exitsub Else Application.EnableEvents = False Newvalue = Target.Value Application.Undo Oldvalue = Target.Value Target.Value = Newvalue If Oldvalue <> "" Then If Newvalue <> "" Then If InStr(1, Oldvalue, ", " & Newvalue & ",") > 0 Then Oldvalue = Replace(Oldvalue, Newvalue & ", ", "") ' If it's in the middle with comma Target.Value = Oldvalue GoTo jumpOut End If If Left(Oldvalue, Len(Newvalue & ", ")) = Newvalue & ", " Then Oldvalue = Replace(Oldvalue, Newvalue & ", ", "") ' If it's at the start with comma Target.Value = Oldvalue GoTo jumpOut End If If Right(Oldvalue, Len(", " & Newvalue)) = ", " & Newvalue Then Oldvalue = Left(Oldvalue, Len(Oldvalue) - Len(", " & Newvalue)) ' If it's at the end with a comma in front of it Target.Value = Oldvalue GoTo jumpOut End If If Oldvalue = Newvalue Then ' If it is the only item in string Oldvalue = "" Target.Value = Oldvalue GoTo jumpOut End If Target.Value = Oldvalue & ", " & Newvalue End If jumpOut: End If End If End If Application.EnableEvents = True Exitsub: Application.EnableEvents = True End Sub
I have posted this on the following Group, https://chandoo.org/forum/threads/mu...own-box.57155/





Reply With Quote