[英]Copying worksheets from multiple workbooks into one workbook pasting to the right
I would really appreciate some help right now.我现在真的很感激一些帮助。
I am trying to take a range of cells F37:F53
from Sheet1
of multiple workbooks and paste it into Sheet1
of a new workbook.我试图从多个工作簿的
Sheet1
中获取一系列单元格F37:F53
并将其粘贴到新工作簿的Sheet1
中。 The one issue I am having is that all the data pastes down in one column.我遇到的一个问题是所有数据都粘贴在一列中。 What I actually want is each set of data to paste to the column to the right.
我真正想要的是将每组数据粘贴到右侧的列中。 So in other words
F37:F53
of workbook 1 should be pasted into A1
of the final workbook.因此,换句话说,工作簿 1 的
F37:F53
应粘贴到最终工作簿的A1
中。 Then F37:F53
of workbook 2 should be pasted into B1
of the final workbook.然后将工作簿 2 的
F37:F53
粘贴到最终工作簿的B1
中。 So on and so forth with a limit of 365 columns以此类推,限制为 365 列
I would really appreciate some help as I am fairly new to VBA我真的很感激一些帮助,因为我对 VBA 还很陌生
Thank you in advance!先感谢您!
Here is what I have so far:这是我到目前为止所拥有的:
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
Set dirObj = mergeObj.Getfolder("C:\Users\a0086850\Documents\421\2017")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
Range("F37:F53" & Range("F65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets("2017").Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End Sub
Assuming the FSO bit is right, try this假设 FSO 位是正确的,试试这个
Sub simpleXlsMerger()
Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Dim c As Long
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")
Set dirObj = mergeObj.Getfolder("C:\Users\a0086850\Documents\421\2017")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
c = c + 1
bookList.Sheets(1).Range("F37:F53").Copy ThisWorkbook.Worksheets("2017").Cells(1, c)
bookList.Close
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.