如何将多个excel表格汇总到一个表格里
来源:百度知道 编辑:UC知道 时间:2024/05/17 22:51:45
用这段代码试下,复制来的,是读入同一目录下的所有工作簿:
Private Sub CommandButton1_Click()
Dim Wk As Workbook, Sht As Worksheet, n As Integer, MyPath, MyName, u As Integer, arr
Application.ScreenUpdating = False
Application.EnableEvents = False
n = 0: M = 0
MyPath = ThisWorkbook.Path
MyName = Dir(MyPath & "\" & "*.xls")
ThisWorkbook.Sheets("sheet1").Columns("A:A").Interior.ColorIndex = 0
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
Set Wk = Workbooks.Open(MyPath & "\" & MyName)
M = M + 1
For Each Sht In Wk.Sheets
arr = Sht.UsedRange
If IsArray(arr) = False Then GoTo PP
n = n + 1
With ThisWorkbook.Sheets("sheet1")
u = .UsedRan