Copy Horizontal and paste vertically

BombSheels

New Member
Joined
Apr 16, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello Experts,
I've been trying to modify this macro i've found in the forum.
In my source file, i need to copy data from Column BH-BK and paste the data in another sheet vertically, to be paste in column BK.
i have more than 200 rows to be copied

Here's my code:
Sub Sin3()
Dim Ary As Variant, Nary As Variant
Dim r As Long, nr As Long

Ary = Sheets("COPY DATA").Range("BH3").CurrentRegion.Value2
ReDim Nary(1 To UBound(Ary) * (UBound(Ary, 2) + 1), 1 To 1)

For r = 3 To UBound(Ary)
nr = nr + 1
Nary(nr, 1) = Ary(r, 1): Nary(nr + 1, 1) = Ary(r, 2): Nary(nr + 2, 1) = Ary(r, 3): Nary(nr + 3, 1) = Ary(r, 4)
nr = nr + 3
Next r
Sheets("PENETRATE").Range("BK8").Resize(nr).Value = Nary
End Sub

COPY DATA SHEET
1659064144979.png


PENETRATE SHEET
1659064260528.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You only talk about copying to column BK but it would appear from your image that columns BI & BJ should contain rows 1 and 2 respectively.
Your percentages in Column BJ seem to be out of alignment with the values in BK.

Should the code be filling in columns BI & BJ as well ?
If so will Column BI just repeat 1-4 for each group ?
 
Upvote 0
You only talk about copying to column BK but it would appear from your image that columns BI & BJ should contain rows 1 and 2 respectively.
Your percentages in Column BJ seem to be out of alignment with the values in BK.

Should the code be filling in columns BI & BJ as well ?
If so will Column BI just repeat 1-4 for each group ?
Hello Alex,
Thank you :)
Column BI-BJ are fixed till row 1000. So copying only from DATA SHEET is from Row 3 downward to be paste in BK in PENETRATE sheet.
 
Upvote 0
See if this works for you:

VBA Code:
Sub Sin3_Transpose()
    Dim Ary As Variant, Nary As Variant
    Dim r As Long, nr As Long, col As Long
    Dim shtCopyData As Worksheet
    Dim shtPaste As Worksheet
    Dim rngPaste As Range
    Dim lastRowCopy As Long
      
    Set shtCopyData = Worksheets("COPY DATA")
    Set shtPaste = Worksheets("PENETRATE")
    Set rngPaste = shtPaste.Range("BK8")
    
    lastRowCopy = shtCopyData.Cells(Rows.Count, "BH").End(xlUp).Row
    
    Ary = shtCopyData.Range("BH3:BK" & lastRowCopy).Value2
    ReDim Nary(1 To UBound(Ary) * (UBound(Ary, 2) + 1), 1 To 1)
    
    For r = 1 To UBound(Ary)
        For col = 1 To UBound(Ary, 2)
            nr = nr + 1
            Nary(nr, 1) = Ary(r, col)
        Next col
    Next r
    rngPaste.Resize(nr).Value = Nary
End Sub
 
Upvote 0
See if this works for you:

VBA Code:
Sub Sin3_Transpose()
    Dim Ary As Variant, Nary As Variant
    Dim r As Long, nr As Long, col As Long
    Dim shtCopyData As Worksheet
    Dim shtPaste As Worksheet
    Dim rngPaste As Range
    Dim lastRowCopy As Long
     
    Set shtCopyData = Worksheets("COPY DATA")
    Set shtPaste = Worksheets("PENETRATE")
    Set rngPaste = shtPaste.Range("BK8")
   
    lastRowCopy = shtCopyData.Cells(Rows.Count, "BH").End(xlUp).Row
   
    Ary = shtCopyData.Range("BH3:BK" & lastRowCopy).Value2
    ReDim Nary(1 To UBound(Ary) * (UBound(Ary, 2) + 1), 1 To 1)
   
    For r = 1 To UBound(Ary)
        For col = 1 To UBound(Ary, 2)
            nr = nr + 1
            Nary(nr, 1) = Ary(r, col)
        Next col
    Next r
    rngPaste.Resize(nr).Value = Nary
End Sub
It works perfectly!!!!! :) Thank you so much Alex :)
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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