【Excel】第六讲-如何快速汇总文件夹的Excel表数据

许多人会遇到这样的困扰,如何快速汇总文件里的Excel数据或Excel其他工作表的数据???不会的朋友肯定是把一个个Excel文件打开,然后复制...粘贴....其实,利用Excel-VB编程可以快速实现这个功能。
具体代码如下:
Sub 汇总数据()
Dim bt As Range, r As Long, c As Long
r = 1
c = 5
Range(Cells(r + 1, "A"), Cells(1048576, c)).ClearContents
Application.ScreenUpdating = False
Dim FileName As String, wb As Workbook, Erow As Long, fn As String, arr As Variant
FileName = Dir(ThisWorkbook.Path & "*.xlsx")
Do While FileName <> ""
If FileName <> ThisWorkbook.Name Then
Erow = Range("A1").CurrentRegion.Rows.Count + 1
fn = ThisWorkbook.Path & "" & FileName
Set wb = GetObject(fn) '
Set sht = wb.Worksheets(1)
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(1048576, "B").End(xlUp).Offset(0, 5))
Cells(Erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
wb.Close False
End If
FileName = Dir
Loop
Application.ScreenUpdating = True
End Sub
如图所示:


【Excel】第六讲-如何快速汇总文件夹的Excel表数据_第1张图片
第六讲.gif

今天的Excel分量是不是很足?用到了编程,有没有很高大上?想要学习更多的你,我们明天不见不散。

你可能感兴趣的:(【Excel】第六讲-如何快速汇总文件夹的Excel表数据)