按Alt+F11,調出Visual Basic 界面。
在左側窗口中,右鍵選擇==“插入”—“模塊”==:
將如下代碼粘貼進去,點擊運行按鈕,完成數據表合并。
Sub MergeAllSheetsInThisWorkbook()
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set st = Worksheets.Add(before:=Sheets(1))
st.Name = "merged"
For Each shet In Sheets:
If shet.Name <> "merged" Then
i = st.Range("A" & Rows.Count).End(xlUp).Row + 1
shet.UsedRange.Copy
st.Cells(i, 1).PasteSpecial Paste:=xlPasteAll
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Done!!!"
End Sub