Need help with custom transpose pasting

TXkleen

New Member
Joined
Oct 19, 2017
Messages
9
I have a large data set, that is made up of 4 columns. I would like to be able to somehow quickly copy all of the data, and paste it into one column. As an example:

Raw Data:
B1, B2, B3, B4
C1, C2, C3, C4
D1, D2, D3, D4
...
Z1, Z2, Z3, Z4

Desired format of pasted/transposed data all into one column:
B1
B2
B3
B4
C1
C2
C3
C4
D1
D2
D3
D4
...
Z1
Z2
Z3
Z4

Any ideas?


Thanks!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Macro is likely to be quickest way to do that.

What cell does your data start in and what is the name of that sheet? Is it always 4 columns wide?
What sheet do you want the single column to be in and in which column?
 
Upvote 0
Data starts in B1. Sheet is always Sheet1, as I am pasting the data in from another file and creating a new file with it.
Data is always 4 columns wide.

Single column of data pasted into column G of Sheet 1 would be great.

Thank you
 
Upvote 0
Try:
Code:
Sub SingleCol()

    Dim x       As Long
    Dim y       As Long
    Dim i       As Long
    
    Dim arr()   As Variant
    Dim arrO()  As Variant
    
    With Sheets("Sheet1")
        y = .Cells(.Rows.count, 2).End(xlUp).row
        arr = .Cells(1, 2).Resize(y, 4).Value
        arrO = .Cells(1, 2).Resize(y * 4).Value
    End With
    
    i = LBound(arrO, 1)
    For x = LBound(arr, 1) To UBound(arr, 1)
        For y = 1 To 4
            arrO(i, UBound(arrO, 2)) = arr(x, y)
            i = i + 1
        Next y
    Next x
    
    Sheets("Sheet1").Cells(1, 7).Resize(UBound(arrO, 1), UBound(arrO, 2)).Value = arrO
        
    Erase arr
    Erase arrO
    
End Sub
 
Last edited:
Upvote 0
[TABLE="width: 576"]
<colgroup><col width="64" span="9" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl22, width: 64"]b1[/TD]
[TD="width: 64"]b2[/TD]
[TD="width: 64"]b3[/TD]
[TD="width: 64"]b4[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="class: xl22"]c1[/TD]
[TD]c2[/TD]
[TD]c3[/TD]
[TD]c4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]d1[/TD]
[TD]d2[/TD]
[TD]d3[/TD]
[TD]d4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]e1[/TD]
[TD]e2[/TD]
[TD]e3[/TD]
[TD]e4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]f1[/TD]
[TD]f2[/TD]
[TD]f3[/TD]
[TD]f4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]g1[/TD]
[TD]g2[/TD]
[TD]g3[/TD]
[TD]g4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]b1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]b2[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]this macro does what you want[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]b3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]b4[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]if you attach it to a shape[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]c1[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]clicking on that shape[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]c2[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]will run the macro[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl22"]c3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]c4[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Sub Macro4()[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]d1[/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]d2[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]' Macro4 Macro[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]d3[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 4"]' Macro recorded 14/11/2017 by bob[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]d4[/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e2[/TD]
[TD][/TD]
[TD][/TD]
[TD]'[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e3[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] rrow = 9[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e4[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] For j = 1 To 6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]f1[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] For k = 1 To 4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]f2[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] rrow = rrow + 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]f3[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"] Cells(rrow, 1) = Cells(j, k)[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]f4[/TD]
[TD][/TD]
[TD][/TD]
[TD] Next k[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]g1[/TD]
[TD][/TD]
[TD][/TD]
[TD] Next j[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]g2[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"] End Sub[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]g3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]g4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Try:
Code:
Sub SingleCol()

    Dim x       As Long
    Dim y       As Long
    Dim i       As Long
    
    Dim arr()   As Variant
    Dim arrO()  As Variant
    
    With Sheets("Sheet1")
        y = .Cells(.Rows.count, 2).End(xlUp).row
        arr = .Cells(1, 2).Resize(y, 4).Value
        arrO = .Cells(1, 2).Resize(y * 4).Value
    End With
    
    i = LBound(arrO, 1)
    For x = LBound(arr, 1) To UBound(arr, 1)
        For y = 1 To 4
            arrO(i, UBound(arrO, 2)) = arr(x, y)
            i = i + 1
        Next y
    Next x
    
    Sheets("Sheet1").Cells(1, 7).Resize(UBound(arrO, 1), UBound(arrO, 2)).Value = arrO
        
    Erase arr
    Erase arrO
    
End Sub



Perfect. Thank you sir!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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