excel多表格合并教程
excel多表格合并教程
在大數(shù)據(jù)分析的時代,辦公講求的事辦公的效率,而又很多數(shù)據(jù)表不在同一文件卻要合并,手動復(fù)制粘貼太慢了,下面是學(xué)習(xí)啦小編帶來的關(guān)于excel多表格合并教程的內(nèi)容,歡迎閱讀!
把需要合并的excel表格文檔放到同一個文件夾里
excel多表格合并教程1:新建一個“數(shù)據(jù)合并.xlsx“文檔
excel多表格合并教程2:打開“數(shù)據(jù)合并.xlsx“文檔,在”Sheet1“工作表的地方右鍵→查看代碼(快捷鍵:“Alt+F11”,盡量選用快捷方式)進(jìn)入到Microsoft Visual Basic for Applications窗口
excel多表格合并教程3:雙擊工程資源管理器里面的sheet1,在右側(cè)的代碼區(qū)粘貼如下代碼:
Sub 合并當(dāng)前目錄下所有工作簿的全部工作表()
Dim MyPath, MyName, AWbName
Dim Wb As Workbook, WbN As String
Dim G As Long
Dim Num As Long
Dim BOX As String
Application.ScreenUpdating = False
MyPath = ActiveWorkbook.Path
MyName = Dir(MyPath & "\" & "*.xls")
AWbName = ActiveWorkbook.Name
Num = 0
Do While MyName <> ""
If MyName <> AWbName Then
Set Wb = Workbooks.Open(MyPath & "\" & MyName)
Num = Num + 1
With Workbooks(1).ActiveSheet
.Cells(.Range("A65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) - 4)
For G = 1 To Sheets.Count
Wb.Sheets(G).UsedRange.Copy .Cells(.Range("A65536").End(xlUp).Row + 1, 1)
Next
WbN = WbN & Chr(13) & Wb.Name
Wb.Close False
End With
End If
MyName = Dir
Loop
Range("A1").Select
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "個工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
End Sub
excel多表格合并教程4:運(yùn)行→運(yùn)行子過程/用戶窗體(或者直接點(diǎn)擊運(yùn)行按鈕,快捷鍵:F5),即可合并所有Excel表格到”數(shù)據(jù)合并.xlsx“文檔的Sheet1工作表里面
excel多表格合并教程5:完成Excel表格的合并