Dear all,
I need to transpose Columns B:N based on unique values in Column A to rows. I have already found a VBA script on this forum that acomplishes this to a degree:
It was posted in this thread: Transpose Unique Values in column to row
by user DanteAmor
I would appreciate if someone would give me some guidance how to expand this script where you have more than three columns. Thank you. Your help is greatly appreciated.
I need to transpose Columns B:N based on unique values in Column A to rows. I have already found a VBA script on this forum that acomplishes this to a degree:
It was posted in this thread: Transpose Unique Values in column to row
by user DanteAmor
VBA Code:
Sub TransposeColumns()
Dim a As Variant, b() As Variant
Dim dic As Object, i As Long, lin As Long, col As Long, n As Long
Dim lr As Long
lr = ActiveSheet.Range("A:C").Find("*", , xlValues, , xlByRows, xlPrevious).Row
Set dic = CreateObject("Scripting.Dictionary")
a = Range("A2:C" & lr).Value2
Range("D2", Cells(Rows.Count, Columns.Count)).ClearContents
For i = 1 To UBound(a)
dic(a(i, 1)) = dic(a(i, 1)) + 1
If dic(a(i, 1)) > n Then n = dic(a(i, 1))
Next
n = (n * 2) + 1
ReDim b(1 To dic.Count, 1 To n)
dic.RemoveAll
For i = 1 To UBound(a)
If Not dic.exists(a(i, 1)) Then
lin = lin + 1
col = 1
b(lin, col) = a(i, 1)
Else
lin = Split(dic(a(i, 1)), "|")(0)
col = Split(dic(a(i, 1)), "|")(1) + 2
End If
dic(a(i, 1)) = lin & "|" & col
b(lin, col + 1) = a(i, 2)
b(lin, col + 2) = a(i, 3)
Next
Application.ScreenUpdating = False
Range("E2").Resize(dic.Count, n).Value = b
Application.ScreenUpdating = True
End Sub
I would appreciate if someone would give me some guidance how to expand this script where you have more than three columns. Thank you. Your help is greatly appreciated.