Question : Excel VBA - append ID for each row to results

The attached file has some code which loops and combines all the columns into one column, with label-strings appended to the beginning.  The code was written to start with the first column (on the SurveyText sheet) and combine all.
Now, I've added another column (col. A) with an ID number for each row.  So, the combine-column function should start with the second column.  Plus, it should add the ID code to each cell in the row at the end (this way, the final results in the single-combined column can be traced back to the original row number).

This code was written by StephenJR and it is very compact and elegant (in my, beginner's opinion) and as such -- I still cannot figure out how it works.
Any help you can provide will be greatly appreciated!
Attachments:
 
 

Answer : Excel VBA - append ID for each row to results

This should do the trick

Public Sub CombineColumns()

Dim r As Long, c As Long

With Sheets("surveyText")
    For c = 2 To .Cells(1, .Columns.Count).End(xlToLeft).Column - 1 Step 2
        For r = 2 To .Cells(.Rows.Count, c).End(xlUp).Row
            Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp)(2) = .Cells(r, 1) & " - " & .Cells(r, c) & "_" & .Cells(1, c) & "- " & .Cells(r, c + 1)
        Next r
    Next c
End With

End Sub
Random Solutions  
 
programming4us programming4us