JohnBell79
New Member
- Joined
- Jul 19, 2023
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
Hi,
I have written this code, with a little help from this forum. I am now looking to add in a "," between selections so that the cell does not automatically try to wrap the text.
So hopefully finished cell would look like this
Instead of this
Thanks you.
I have written this code, with a little help from this forum. I am now looking to add in a "," between selections so that the cell does not automatically try to wrap the text.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim old_val As String
Dim new_val As String
Application.EnableEvents = True
On Error GoTo Exitsub
If (Target.Column = 3) And (Target.Row > 1) Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
new_val = Target.Value
Application.Undo
old_val = Target.Value
If old_val = "" Then
Target.Value = new_val
Else
If InStr(1, old_val, new_val) = 0 Then
Target.Value = old_val & vbNewLine & new_val
Else:
Target.Value = old_val
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
So hopefully finished cell would look like this
Instead of this
Thanks you.
Last edited by a moderator: