繁体   English   中英

我想将文件夹中多个Excel工作簿中的数据合并到单个Excel工作表中

[英]I want to merge data from multiple excel workbooks in a folder into single excel sheet

我必须从多个Excel文件中选择单行(第9行)数据(每个文件中5行(第6-10行)数据)。 所有这些文件都在单个文件夹中,合并文件的文件结构上一层。 在给定的代码下面复制4(第6-9行)行。 请帮忙:

使用的代码如下:

Sub Auto_Open()
    'MsgBox "Welcome to ANALYSIS TABS"
    'End Sub

    'Sub simpleXlsMerger()
    Dim bookList As Workbook
    Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object

    MsgBox "Welcome to Merging Platform..."

    Application.ScreenUpdating = True
    Set mergeObj = CreateObject("Scripting.FileSystemObject")

    'change folder path of excel files here
    Set dirObj = mergeObj.Getfolder("C:\Users\00508069\Desktop\New folder\data")
    Set filesObj = dirObj.Files
    For Each everyObj In filesObj
    Set bookList = Workbooks.Open(everyObj)

    'change "A2" with cell reference of start point for every files here
    'for example "B3:IV" to merge all files start from columns B and rows 3
    'If you're files using more than IV column, change it to the latest column
    'Also change "A" column on "A65536" to the same column as start point

    Range("A9:IV" & Range("A10").End(xlUp).Row).Copy

    ThisWorkbook.Worksheets(1).Activate

    'Do not change the following column. It's not the same column as above
    Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial


    Application.CutCopyMode = False
    bookList.Close
    Next
End Sub

问题是在这条线

Range("A9:IV" & Range("A10").End(xlUp).Row).Copy

在这部分更严格

Range("A10").End(xlUp).Row

表示“从单元格A10到数据块结束的单元格并获取该单元格的行号”。 在您的情况下,它意味着6。

改用它,你会没事的

Range("A9:IV9").Copy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM