|
楼主 |
发表于 2016-9-25 21:10
|
显示全部楼层
下面是标准一点的
不限文件数量,不限工作表个数
- Sub 标准汇总方式()
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
-
- Set SHX = Sheets("TEMPXX")
- SHX.Range("A2:D1048576").ClearContents
-
- FileArr = FileAllArr(ThisWorkbook.Path, "*.xls?", ThisWorkbook.Name, True, False)
- For I = 0 To UBound(FileArr)
-
- Str_coon = "HDR=yes';Data Source =" & FileArr(I) '//OFFICE2003,2007 通用
- NameArr = GET_NameSheets(Str_coon)
- For N = 0 To UBound(NameArr)
- StrSQL = "SELECT 站点,单量"
- StrSQL = StrSQL & ",'" & NameArr(N) & "' AS 工作表"
- StrSQL = StrSQL & ",'" & GetPathFromFileName(FileArr(I)) & "' AS 工作簿"
- StrSQL = StrSQL & " FROM [" & NameArr(N) & "$]"
- IROW = SHX.Range("A1048576").End(3).Row + 1
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
- SHX.Range("A" & IROW).Resize(UBound(SQLARR, 1) + 1, UBound(SQLARR, 2) + 1) = SQLARR '//(0 TO X)的数组行列都要+1,(1 TO X) 的不要
- Next N
-
- Next I
- Set SH0 = Sheets("汇总")
- SH0.Range("A2:B1048576").ClearContents
-
- StrSQL = "SELECT 站点,SUM(单量) as 单量 FROM [" & SHX.Name & "$] GROUP BY 站点 ORDER BY 站点"
- Str_coon = "HDR=yes';Data Source=" & ThisWorkbook.FullName
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
-
- 'MsgBox StrSQL
- SH0.Range("A2").Resize(UBound(SQLARR, 1) + 1, UBound(SQLARR, 2) + 1) = SQLARR
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|