|
smartelfs 发表于 2014-10-11 16:49
源表中AH-AJ列有数据
但是,AH-AJ 三列在合并后的表里 不显示啊 大神~~ - Sub test()
- Dim cFile$, cPath$, now$, Sh As Workbook, i As Integer, ar, ix As Integer, io As Integer
- Set Sh = ActiveWorkbook
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- t = 3 't=1只显示总计 ,t=0 显示明细和总计,t=3 显示明细
- cPath = ThisWorkbook.Path & ""
- cFile = Dir(cPath & "*.csv")
- Sh.Sheets(1).Range("a3:ak5000").Clear
- Do While cFile <> ""
- If cFile <> "汇总表.xls" Then
- Workbooks.Open cPath & cFile
- With ActiveWorkbook
- i = 1
- a = .Sheets(i).Range("u65536").End(xlUp).Row
- ar = .Sheets(i).Range("a6:ak" & a)
- Sh.Sheets(i).Range("a" & Sh.Sheets(i).Range("u65536").End(xlUp).Row + 1).Resize(UBound(ar), 37) = ar
- Erase ar
- nn = nn + 1
- .Close
- End With
- End If
- cFile = Dir
- Loop
-
- ix = 1
- If t <> 3 Then
- ReDim ar(1 To 1, 1 To 37)
- ar(1, 1) = "总计"
- For jx = 2 To 37
- With Sheets(ix)
- ar(1, jx) = Application.Sum(.Range(.Cells(3, jx), .Cells(.Range("u65536").End(xlUp).Row, jx)))
- End With
- Next jx
- If t = 1 Then Sheets(ix).Rows("3:" & Sheets(ix).Range("u65536").End(xlUp).Row + 2).Delete Shift:=xlUp
- Sheets(ix).Range("a" & Sheets(ix).Range("u65536").End(xlUp).Row + 2).Resize(1, 37) = ar
- Erase ar
- End If
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- MsgBox "作业完成" & vbCrLf & "共合并了" & nn & "个工作簿"
- End Sub
复制代码 替换即可 |
|