Sub TransposeData()
Dim LastR As Long, LastC As Long
Dim arr As Variant
Dim DestR As Long
Dim CounterR As Long, CounterC As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationAutomatic
End With
With ThisWorkbook.Worksheets("List")
LastR = .Cells(.Rows.Count, "a").End(xlUp).Row
LastC = .Cells(1, .Columns.Count).End(xlToLeft).Column
arr = .Range(.Cells(LastR, "a"), .Cells(1, LastC)).Value
End With
Worksheets.Add
DestR = 1
With ActiveSheet
.Range("a1:c1") = Array("Client", "Code", "Fund#")
For CounterR = 2 To UBound(arr, 1)
For CounterC = 3 To UBound(arr, 2)
If Trim(arr(CounterR, CounterC)) <> "" Then
DestR = DestR + 1
.Cells(DestR, 1) = arr(1, CounterC)
.Cells(DestR, 2) = arr(CounterR, 1)
.Cells(DestR, 3) = arr(CounterR, 2)
End If
Next
Next
.Columns.AutoFit
.[a1].Sort Key1:=.[a1], Key2:=.[c2], Order1:=xlAscending, Order2:=xlAscending, Header:=xlYes
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
MsgBox "Done"
End Sub
|