Try this adaptation

[vba]

Public Sub JoinData()
Dim NumRows As Long
Dim NumCols As Long
Dim LastCol As Long
Dim cell As Range
Dim tmp As String
Dim j As Long

NumRows = Selection.Rows.Count
NumCols = Selection.Columns.Count

If NumCols = 1 Then

For j = 1 To NumRows

tmp = tmp & Selection.Cells(j, 1).Value & " "
Next j

Selection.Value = ""
Selection.Cells(1, 1).Value = Trim(tmp)
Else

For Each cell In Selection.Columns(1).Cells

tmp = ""
With cell

LastCol = Cells(.Row, Columns.Count).End(xlToLeft).Column
For j = .Column To LastCol

tmp = tmp & Cells(.Row, j).Value & " "
Next j

Cells(.Row, .Column).Resize(1, LastCol - .Column + 1).Value = ""
Cells(.Row, .Column).Value = Trim(tmp)
End With
Next cell
End If
End Sub
[/vba]