vba to paste special - transpose

Smithsat34

Board Regular
Joined
Jan 20, 2014
Messages
54
Hi Board,

Am a little out of practise with VBA. I'm getting a 438 error on the macro below.
I'm trying to copy the content of column A, in blocks of 5 rows and transpose into 5 columns on sheet 3.


Sub Macro4()

Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim lastRow As Long

x = 1
y = 5
z = 1

lastRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row


For A = 1 To lastRow


Worksheets("Sheet2").Range("A" & x & ":A" & y).Copy

Worksheets("Sheet3").Range("A" & z).Selection.PasteSpecial Transpose:=True


x = x + 5
y = y + 5
z = z + 1

Next A
End Sub

The error message appears at the paste line.

Thanks in advance

bob
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Remove the word "Selection"
 
Upvote 0
Selection is the selected cells on the activesheet & you use it like
Code:
Selection.Copy
You cannot use it in the manner you tried
 
Upvote 0
You may want to try this:
Code:
Sub New_One()
'Modified 5/8/18 10:35 AM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim b As Long
b = 1
Dim lastRow As Long
lastRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To lastRow Step 5
        Sheets(2).Cells(i, 1).Resize(5).Copy
        Sheets(3).Cells(b, 1).PasteSpecial Transpose:=True
        b = b + 1
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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