0

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

enter image description here

Community
  • 1
  • 1
Cris Reis
  • 179
  • 6
  • 16

2 Answers2

1

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
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80
0

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.

Gary's Student
  • 95,722
  • 10
  • 59
  • 99