=TEXTJOIN(", ",TRUE,IF(A2:AV2<>"",$A$1:$AV$1,""))
Confirm with Ctrl+Shift+Enter and copy it down.Sub CustomConcatenate()
Dim ws As Worksheet
Dim lr As Long, lc As Long, i As Long, j As Long
Dim x, y()
Dim str As String
Application.ScreenUpdating = False
Set ws = ActiveSheet
lr = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lc = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
x = ws.Range("A1", ws.Cells(lr, lc)).Value
ReDim y(1 To UBound(x, 1) - 1, 1 To 1)
For i = 2 To UBound(x, 1)
For j = 1 To UBound(x, 2)
If x(i, j) <> "" Then
If str = "" Then
str = x(1, j)
Else
str = str & ", " & x(1, j)
End If
End If
Next j
y(i - 1, 1) = str
str = ""
Next i
ws.Cells(2, lc + 1).Resize(lr - 1, 1).Value = y
Application.ScreenUpdating = True
MsgBox "Task completed!", vbInformation
End Sub
I'm asking because it would be useful to have a column that could be used to determine how many rows of data there are.
If there is such a thing then this should be straightforward.