Originally Posted by
timculberson
I have a pretty large text file that I've imported into two columns, with data that is essentially listed in repeating sets that I need to re-organize into a proper workable format.
Here is a macro that does it
Sub Test()
Dim iLastRow As Long
Dim iLastCol As Long
Dim iRow As Long
Dim iCol
Dim i As Long
Application.ScreenUpdating = False
iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1").Copy Range("C1")
Range("B1").Copy Range("C2")
For i = 2 To iLastRow
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
iCol = Application.Match(Cells(i, "A").Value, Range("C1", Cells(1, iLastCol)), 0)
If IsError(iCol) Then
Cells(i, "A").Copy Cells(1, iLastCol + 1)
Cells(i, "B").Copy Cells(2, iLastCol + 1)
Else
iRow = Cells(Rows.Count, 2 + iCol).End(xlUp).Row + 1
Cells(i, "B").Copy Cells(iRow, 2 + iCol)
End If
Next i
Columns("A:B").Delete
Application.ScreenUpdating = True
End Sub