Input data in first image and result in second, column H.


Input data in first image and result in second, column H.


Try this one:
=SUBSTITUTE(TRIM(SUBSTITUTE(A1,CHAR(10)," "))," ",CHAR(10))
or VBA equivalent:
Sub test()
With Range("D1:D10")
.Replace Chr(10), " "
.Value = Evaluate("INDEX(TRIM(" & .Address & "),)")
.Replace " ", Chr(10)
.WrapText = True
End With
End Sub
Here is a method of concatenation that will avoid any unnecessary separators:
Public Function StitchValues(rIn As Range) As String
Dim r As Range, v As Variant
StitchValues = ""
For Each r In rIn
v = r.Text
If v <> "" Then
If StitchValues = "" Then
StitchValues = v
Else
StitchValues = StitchValues & vbLf & v
End If
End If
Next r
End Function
So in H1 you would enter:
=StitchValues(B1:E1)
and then turn on text-wrapping, adjust row heights, etc.