|
有几个明显的错误,我把你代码全部复制在下面并给你修改了:Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set fso = CreateObject("scripting.filesystemobject")
Set ff = fso.getfolder("C:\Users\Ting\Desktop\test\9.13")
For Each f In ff.Files
For i = 6 To 21
If Left(ThisWorkbook.Sheets(2).Cells(i, 1).Value, 1) = Left(f.Name, 1) Then '是第二个表,第一个表是 360Qex,把sheets(1)改成sheets(2)
Set wo = Workbooks.Open(f)
' r = wo.Sheets(1).Cells(wo.Rows.Count, 1).End(xlUp).Row '这一行不对,用下面的写法
r = wo.Sheets(1).[a10000].End(xlUp).Row
ThisWorkbook.Sheets(2).Cells(i, 2) = wo.Sheets(1).Cells(r - 1, 3) '我建议的写法,你原来的用法仍然保留了,你对比下效果
ThisWorkbook.Sheets(2).Cells(i, 3) = wo.Sheets(1).Cells(r, 3) '这种写法不会把格式带过来,复制会把主表的排版搞得很混乱
wo.Sheets(1).Cells(r - 1, 6).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 6)
wo.Sheets(1).Cells(r, 6).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 7)
wo.Sheets(1).Cells(r - 1, 9).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 10)
wo.Sheets(1).Cells(r, 9).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 11)
wo.Sheets(1).Cells(r - 1, 12).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 14)
wo.Sheets(1).Cells(r, 12).Copy Destination:=ThisWorkbook.Sheets(2).Cells(i, 15)
wo.Close True
End If
Next
Next
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|