I have some code that copies a column of data from multiple closed workbooks and pastes it into a single master workbook.
The code works well so far, but it pastes the data into a single column -it pastes the data from closed workbook 1, then finds the next empty row and pastes the data from closed workbook 2 below it and so on. I need it to 'transpose' the data when it pastes, so the data goes across the row.
I've successfully got the Paste Special Transpose code to work on its own in another workbook but when I try to insert it into my code, to replace the existing Paste lines, I get Runtime error 1004 'PasteSpecial method of Range class failed'
Can someone help?
Here's my code, with the Paste Special part with ' in front
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
Dim Filepath As String
Filepath = "Z:\Functional workstreams\Risk and compliance\Compliance steering group\Life & Limb\RETURNS - 2017\Test\"
MyFile = Dir(Filepath)
Do While Len(MyFile) > 0
Workbooks.Open (Filepath & MyFile)
Range("D3:D24").Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'ActiveSheet.Cells(erow, 1).Select
'Selection.PasteSpecial Paste:=xlPasteAll, operation:=xlNone, skipblanks:=False, Transpose:=True
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 25))
MyFile = Dir
Loop
End Sub