fletchy888,
Thanks for the workbook.
I assume that your raw data is always in worksheet Sheet1. The macro will create a new worksheet Results.
Detach/open workboo ReorgData arrays w1 Aary Bary wR Oary - fletchy888 - EF793907 - SDG16.xls and run macro ReorgData.
If you want to use the macro on another workbook:
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Option Explicit
Option Base 1
Sub ReorgData()
' stanleydgromjr, 09/26/2011
' http://www.excelforum.com/excel-general/793907-multiple-transpose-function-from-rows-into-columns.html
Dim w1 As Worksheet, wR As Worksheet
Dim A(), B(), O(), k
Dim r As Long, n As Long, c As Long, Amax As Long, s As Long, e As Long
Dim d1 As Object
Set w1 = Worksheets("Sheet1")
r = w1.Cells(Rows.Count, 1).End(xlUp).Row
A = w1.Range("A1:A" & r)
B = w1.Range("B1:B" & r)
Set d1 = CreateObject("scripting.dictionary")
For r = 1 To UBound(A)
If Not d1.exists(A(r, 1)) Then
d1(A(r, 1)) = d1.Count
End If
Next r
k = d1.Keys
ReDim O(1 To d1.Count + 1, 1 To 1)
For r = 1 To d1.Count
O(r, 1) = k(r - 1)
Next r
Amax = 0
For r = 1 To UBound(O)
n = Application.CountIf(w1.Columns(1), O(r, 1))
If n > Amax Then Amax = n
Next r
ReDim Preserve O(1 To d1.Count + 1, 1 To Amax + 1)
For r = 1 To d1.Count
s = Application.Match(O(r, 1), A, 0)
e = Application.Match(O(r, 1), A, 1)
n = 1
If s = e Then
O(r, 2) = B(s, 1)
Else
For c = s To e Step 1
n = n + 1
O(r, n) = B(c, 1)
Next c
End If
Next r
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
wR.Range("A1").Resize(UBound(O), Amax + 1).Value = O
wR.UsedRange.Columns.AutoFit
wR.Activate
End Sub
Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm
Then run the ReorgData macro.
Bookmarks