我有20-22个单独的电子表格,我想将其合并到单个电子表格中。有没有办法做到这一点?
答案 0 :(得分:1)
要将其合并到单个电子表格中,请使用以下VB代码 首先将所有电子表格合并到单个文件夹
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")
在此处更改Excel文件的文件夹路径
Set dirObj = mergeObj.Getfolder("Folder path (Consolidated spreadsheet folder path")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)
改变" A1"这里有每个文件的起始点的单元格引用 如果您使用的是超过IV列的文件,请将其更改为最新列 同时改变" A"专栏" A65536"与起点相同的列
Range("A1:IV" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Application.CutCopyMode = False
bookList.Close
Next
End Sub