OK, if you want the results to appear in a single cell then you'll need some form of VBA to do this.
Copy the code below and paste it into a general module.
Function aconcat(a As Variant, Optional sep As String = "") As String
'VBA code by Harlan Grove
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
Assuming your data is in the range A2:A8, enter this array formula** in B2:
=SUBSTITUTE(TRIM(aconcat(IF(A2:A8=1," "&ROW(A2:A8)-ROW(A2)+1,"")))," ",", ")
** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
Bookmarks