Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1453|回复: 3

[已解决]表册汇总

[复制链接]
发表于 2013-3-20 20:40 | 显示全部楼层 |阅读模式
请教如何将多个表内容汇总到一个表中,具体要求在附件中的汇总表中。
最佳答案
2013-3-20 21:17
本帖最后由 hwc2ycy 于 2013-3-20 21:19 编辑


放到要汇总的工作簿同一目录下。

表汇总.zip

8.14 KB, 下载次数: 18

发表于 2013-3-20 21:11 | 显示全部楼层
  1. Sub 汇总()
  2.     Dim file$, path$
  3.     Dim wb As Workbook
  4.     Dim arr(), lCount&
  5.     Dim arrPos, j As Byte
  6.     Application.ScreenUpdating = False
  7.     arrPos = Array("a3", "b3", "b4", "b5", "b6", "b7")
  8.     path = ThisWorkbook.path & Application.PathSeparator
  9.     file = Dir(path & "*.xls", vbNormal + vbDirectory)
  10.     Do While Len(file) > 0
  11.         If file <> ThisWorkbook.Name Then
  12.             lCount = lCount + 1
  13.             ReDim Preserve arr(1 To 6, 1 To lCount)
  14.             Set wb = GetObject(path & file)
  15.             With wb.Worksheets("sheet1")
  16.                 For j = 1 To UBound(arr)
  17.                     arr(j, lCount) = "'" & .Range(arrPos(j - 1))
  18.                 Next
  19.             End With
  20.             wb.Close False
  21.         End If
  22.         file = Dir

  23.     Loop
  24.     Range("a" & Cells(Rows.Count, 1).End(xlUp).Row + 1).Resize(lCount, 6) = WorksheetFunction.Transpose(arr)
  25.     Application.ScreenUpdating = True
  26.     MsgBox "汇总完成"
  27. End Sub
复制代码
回复

使用道具 举报

发表于 2013-3-20 21:13 | 显示全部楼层
本帖最后由 hwc2ycy 于 2013-3-20 21:18 编辑
  1. Sub 汇总()
  2.     Dim file$, path$
  3.     Dim wb As Workbook
  4.     Dim arr(), lCount&
  5.     Dim arrPos, j As Byte
  6.     Application.ScreenUpdating = False
  7.     arrPos = Array("a3", "b3", "b4", "b5", "b6", "b7")
  8.     path = ThisWorkbook.path & Application.PathSeparator
  9.     file = Dir(path & "*.xls", vbNormal + vbDirectory)
  10.     Do While Len(file) > 0
  11.         If file <> ThisWorkbook.Name Then
  12.             lCount = lCount + 1
  13.             ReDim Preserve arr(1 To 6, 1 To lCount)
  14.             Set wb = GetObject(path & file)
  15.             With wb.Worksheets("sheet1")
  16.                 For j = 1 To UBound(arr)
  17.                     arr(j, lCount) = "'" & .Range(arrPos(j - 1))
  18.                 Next
  19.             End With
  20.             wb.Close False
  21.         End If
  22.         file = Dir
  23.     Loop
  24.     Range("a" & Cells(Rows.Count, 1).End(xlUp).Row + 1).Resize(lCount, 6) = WorksheetFunction.Transpose(arr)
  25.     Range("a1").CurrentRegion.Borders.LineStyle = xlContinuous
  26.     Application.ScreenUpdating = True
  27.     MsgBox "汇总完成"
  28. End Sub
复制代码
回复

使用道具 举报

发表于 2013-3-20 21:17 | 显示全部楼层    本楼为最佳答案   
本帖最后由 hwc2ycy 于 2013-3-20 21:19 编辑


放到要汇总的工作簿同一目录下。

终结性评价汇总表.rar

9.74 KB, 下载次数: 24

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 22:59 , Processed in 0.557969 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表