I have a data set similar to the below:
I would like to convert the data to multiple columns where duplicate ID's (column 1) are removed and all other data is consolidated into single rows split across columns.
I have tried the following code from another thread:
Convert columns with multiple rows of data to rows with multiple columns in Excel.
However this results in column two data also being consolidated across columns where there are duplicates in rows.
For example, the above table would appear as
I need to amend the code so that it only removes duplicated data in column 1 and spreads the remaining data across columns.
I would like the data to end as follows:
Below is the code i'm using:
Sub ConsolidateRows_SpreadAcross()
Dim lastRow As Long, i As Long, j As Long
Dim colMatch As Variant, colConcat As Variant
application.ScreenUpdating = False 'disable ScreenUpdating to avoid screen flashes
lastRow = range("A" & Rows.Count).End(xlUp).Row 'get last row
For i = lastRow To 2 Step -1
If Cells(i, 2) = Cells(i - 1, 2) Then
range(Cells(i, 3), Cells(i, Columns.Count).End(xlToLeft)).Copy Cells(i - 1, Columns.Count).End(xlToLeft).Offset(, 1)
Rows(i).Delete
Else
If Cells(i, 1) = Cells(i - 1, 1) Then
range(Cells(i, 2), Cells(i, Columns.Count).End(xlToLeft)).Copy _
Cells(i - 1, Columns.Count).End(xlToLeft).Offset(, 1)
Rows(i).Delete
End If
End If
Next
application.ScreenUpdating = True 'reenable ScreenUpdating
End Sub
Any assistance would be greatly appreciated.