Momo80
Momo80

Reputation: 1

multiple entries drop-down list: line break instead of commas

I'm using a vba code from a tutorial to allow multiple entries from a drop-down list in excel.

The code works fine but it adds a comma for new entries. Instead of commas, I would like line breaks each new entry.

So, instead of a,b,c

I would like

a
b
c

Any suggestion?

Here's the code

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim lUsed As Long
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 Target.Column = 13 Then
If oldVal = "" Then
Else
If newVal = "" Then
Else
lUsed = InStr(1, oldVal, newVal)
If lUsed > 0 Then
Target.Value = oldVal
Else
Target.Value = oldVal _
& ", " & newVal
End If

End If
End If
End If
End If

exitHandler:
Application.EnableEvents = True
End Sub

Upvotes: 0

Views: 1203

Answers (0)

Related Questions