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:

ABCDEDG
1NameAcct
2Mike111111111222222222333333333
3Dave444444444555555555666666666777777777
4Steve888888888
5Sean999999999123456789
6Dana159753456

<tbody>
</tbody>


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:




ABCDE
1NameAcct
2Mike111111111
3Mike222222222
4Mike333333333
5Dave444444444
6Dave555555555

<tbody>
</tbody>

and so on...

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

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,217,371
Messages
6,136,170
Members
449,996
Latest member
duraichandra

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