我必须从多个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
答案 0 :(得分:1)
问题出在这一行
Range("A9:IV" & Range("A10").End(xlUp).Row).Copy
在这部分中更严格
Range("A10").End(xlUp).Row
表示"从单元格A10上升到数据块结束的单元格并获取该单元格的行号#34;。在你的情况下,它意味着6。
改用它,你就没事了
Range("A9:IV9").Copy
答案 1 :(得分:0)