Moving Data From Rows to Columns

williamscheidt

New Member
Joined
Dec 7, 2013
Messages
31
Hi,
I'm an Excel beginner running Excel for Mac 2011. I'm in need of assistance in combining data from pairs of subsequent rows into one row, as in the simplified example below. In reality I have 303 pairs of rows (606 total rows) with 14 columns in each.
Thank you in advance for your time and expertise!
Bill

FROM:
123
456
789
101112

<!--StartFragment--> <colgroup><col width="65" span="3" style="width:65pt"> </colgroup><tbody>
<!--EndFragment--></tbody>

TO:
123456
789101112

<!--StartFragment--> <colgroup><col width="65" span="6" style="width:65pt"> </colgroup><tbody>
<!--EndFragment--></tbody>
 
Thank you! To your questions:
1) Yes, the raw data will always begin in A5 and the last column is always column N
2) In column A, beginning with A5, every other row has a numerical value beginning with 1 and counting up. So A5 has the value of 1. A6 is blank. A7 has the value of 2. A8 is blank. A9 has the value of 3 etc etc
3) In a perfect world the results would be written on a new sheet in the workbook, ideally titled "Post Macro" or something like that. But, I can always copy and paste, so starting two rows below the last used row in column A will be fine :)
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Thank you! To your questions:
1) Yes, the raw data will always begin in A5 and the last column is always column N
2) In column A, beginning with A5, every other row has a numerical value beginning with 1 and counting up. So A5 has the value of 1. A6 is blank. A7 has the value of 2. A8 is blank. A9 has the value of 3 etc etc
3) In a perfect world the results would be written on a new sheet in the workbook, ideally titled "Post Macro" or something like that. But, I can always copy and paste, so starting two rows below the last used row in column A will be fine :)

williamscheidt,

Thanks for the new information.

Here is a macro solution for you to consider, based on the above quote, that uses 2 arrays in memory, and, writes the results to a new worksheet Post Macro.

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



Sample raw data:


Excel 2007
ABCDEFGHIJKLMN
1
2
3
4
51234567891011121314
616171819202122232425262728
72930313233343536373839404142
844454647484950515253545556
95758596061626364656667686970
1072737475767778798081828384
11
Sheet1


After the macro in a new worksheet Post Macro:


Excel 2007
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1123456789101112131416171819202122232425262728
2293031323334353637383940414244454647484950515253545556
3575859606162636465666768697072737475767778798081828384
4
Post 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).

Code:
Sub ReorgDataV3()
' hiker95, 06/09/2015, ME860046
Dim w1 As Worksheet, wp As Worksheet
Dim a As Variant, o As Variant
Dim i As Long, j As Long
Dim lr As Long, nlr As Long, c As Long, nc As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")   '<-- you can change the sheet name here
With w1
  lr = .Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
  a = .Range("A5:N" & lr)
  nlr = (lr - 4) / 2
  ReDim o(1 To nlr, 1 To 28)
End With
For i = 1 To UBound(a, 1) Step 2
  j = j + 1
  For c = 1 To 14
    o(j, c) = a(i, c)
  Next c
  nc = 14
  For c = 1 To 14
    nc = nc + 1
    o(j, nc) = a(i + 1, c)
  Next c
Next i
If Not Evaluate("ISREF(Post Macro!A1)") Then Worksheets.Add(After:=w1).Name = "Post Macro"
Set wp = Sheets("Post Macro")
With wp
  .UsedRange.Clear
  .Cells(1, 1).Resize(UBound(o, 1), UBound(o, 2)) = o
  .Columns(1).Resize(, UBound(o, 2)).AutoFit
  .Activate
End With
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 ReorgDataV3 macro.
 
Upvote 0
Hi Hiker95

Thank you very much! Absolutely perfect! (And sorry for the slow response, I've been on an airplane all day.) I really appreciate your time and expertise with this solution!!

Cheers and have a great evening!
Bill
 
Upvote 0
williamscheidt,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0
Thanks for the invite hiker95! I've got a lot of work ahead of me in the next coming months so there's a good chance you may see me again. :) Already I've found a number of answers just by searching the Q's other have already asked. BTW, I answered my own question regarding dates and times in that fashion. I'm loving this forum!
 
Upvote 0

Forum statistics

Threads
1,216,151
Messages
6,129,162
Members
449,489
Latest member
spvclub

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