Consolidate row data to columns

leebauman

Board Regular
Joined
Jul 1, 2004
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Hello, I need to convert this:
Book20
ABCDEF
1OrderItem 1Item 2Item 3Item 4Item 5
2111AppleOrangeGrape
3222LemonOrangeAppleGrapePear
Sheet1


to this:
Book20
AB
6OrderItem
7111Apple
8111Orange
9111Grape
10222Lemon
11222Orange
12222Apple
13222Grape
14222Pear
Sheet1
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try this code:
VBA Code:
Sub test()
Dim outarr()
rowno = Range("A1").CurrentRegion.Rows.Count
colno = Range("A1").CurrentRegion.Columns.Count
inarr = Range(Cells(1, 1), Cells(rowno, colno))
ReDim outarr(1 To rowno * colno, 1 To 2)
 ' put in headers
 outarr(1, 1) = inarr(1, 1)
 outarr(1, 2) = inarr(1, 2)
 indi = 2
 For i = 2 To rowno
   For j = 2 To 5
    If inarr(i, j) = "" Then
     Exit For
    Else
     outarr(indi, 1) = inarr(i, 1)
     outarr(indi, 2) = inarr(i, j)
     indi = indi + 1
    End If
   Next j
 Next i
 Range(Cells(1, 1), Cells(indi, 2)) = outarr
 
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,275
Messages
6,171,126
Members
452,381
Latest member
Nova88

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