|
再搞一个方法,坛子里的代码组装一下。- Sub hz_2()
- Dim Fso, Fld, Fl
- Dim arr, brr(1 To 4, 1 To 2), i%, j%
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Fld = Fso.getfolder(ThisWorkbook.Path & "\数据")
- If Fld.Files.Count > 0 Then
- Application.ScreenUpdating = False
- For Each Fl In Fld.Files
- Workbooks.Open (Fl)
- arr = ActiveWorkbook.Worksheets(1).[B2:c5] '各表数据域赋给数组arr
- For i = 1 To 4 '逐行
- For j = 1 To 2 '逐列
- If IsNumeric(arr(i, j)) Then brr(i, j) = brr(i, j) + arr(i, j) '如果单元格是数字则累加
- Next
- Next
- ActiveWorkbook.Close
- Next
- Application.ScreenUpdating = True
- ThisWorkbook.Worksheets(1).[B2:c5] = brr '写数据
- MsgBox "数据汇总完成"
- Else
- MsgBox "没有找到任何工作簿文件"
- End If
- End Sub
复制代码 |
|