Horizontal data to vertical data list

miky21

New Member
Joined
Jul 21, 2015
Messages
3
I have a large spreadsheet that has information as follows:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]D[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Acct [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Mike[/TD]
[TD]111111111[/TD]
[TD]222222222[/TD]
[TD]333333333[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Dave[/TD]
[TD]444444444[/TD]
[TD]555555555[/TD]
[TD]666666666[/TD]
[TD]777777777[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Steve[/TD]
[TD]888888888[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Sean[/TD]
[TD]999999999[/TD]
[TD]123456789[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Dana[/TD]
[TD]159753456[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


and so forth and so on.... note the amount of accounts can very by person to the right of the name.

I'm looking to list the account all in one column with the name of the person on the second column. As follows:


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[/TR]
[TR]
[TD]

[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Acct [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Mike[/TD]
[TD]111111111[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[/TR]
[TR]
[TD]3[/TD]
[TD]Mike[/TD]
[TD]222222222[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Mike[/TD]
[TD]333333333[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[/TR]
[TR]
[TD]5[/TD]
[TD]Dave[/TD]
[TD]444444444[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[TD]6[/TD]
[TD]Dave[/TD]
[TD]555555555[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
[TR]
[/TR]
</tbody>[/TABLE]

and so on...

I'm using excel 2010 on windows 7.
Any help would be greatly appreciated.
Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Miky:
In most cases this is not a good ideal. Spreadsheets typically are designed to be used in such a manner:
Rows are designed to be records
Columns are designed to be used as fields.
Doing as you now plan may run you into problems someday if you want to manipulate your data.
 
Upvote 0
This will rearrange your data in place assuming the layout you have shown (data start in A1).
Code:
Sub RearrangeData()
Dim i As Long, lR As Long, ct As Long, V As Variant, M As Long
Application.ScreenUpdating = False
lR = Range("A" & Rows.Count).End(xlUp).Row
For i = lR To 2 Step -1
    ct = Application.CountA(Range(Cells(i, "A"), Cells(i, "A").End(xlToRight)))
    If ct > 2 Then
        M = Application.Max(M, ct)
        V = Cells(i, "A").Offset(0, 2).Resize(1, ct - 2).Value
        With Cells(i, "A")
            .Offset(1, 0).Resize(ct - 2).EntireRow.Insert
            .Resize(ct - 1, 1).FillDown
            .Resize(ct - 2, 1).Offset(1, 1).Value = Application.Transpose(V)
        End With
    End If
Next i
lR = Range("A" & Rows.Count).End(xlUp).Row
Range(Cells(1, "C"), Cells(lR, M)).ClearContents
Application.ScreenUpdating = True
End Sub
 
Upvote 0
miky21,

Here is another macro solution for you to consider that uses two arrays in memory, and, will adjust to the varying number of raw data rows, and, columns.

And, this will also rearrange your data in place assuming the layout you have shown (data start in A1).

You can change the raw data worksheet name in the macro.

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
2. Open your NEW 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
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ReorgData()
' hiker95, 07/22/2015, ME870183
Dim a As Variant, o As Variant, i As Long, j As Long, lR As Long, lc As Long, n As Long, c As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")   '<-- you can change the sheet name here
  lR = .Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
  lc = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
  a = .Range(.Cells(2, 1), .Cells(lR, lc))
  n = Application.CountA(.Range(.Cells(2, 2), .Cells(lR, lc)))
  ReDim o(1 To n, 1 To 2)
  For i = LBound(a, 1) To UBound(a, 1)
    For c = 2 To UBound(a, 2)
      If Not a(i, c) = vbEmpty Then
        j = j + 1: o(j, 1) = a(i, 1): o(j, 2) = a(i, c)
      End If
    Next c
  Next i
  .Range(.Cells(2, 1), .Cells(lR, lc)).ClearContents
  .Cells(2, 1).Resize(UBound(o, 1), UBound(o, 2)) = o
End With
Application.ScreenUpdating = True
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, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ReorgData macro.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top