如何把excel多个sheet合并(百度搜的,非原创)
新建一个Sheet,命名为“All”(名字可随意);右键点击新建Sheet,选择查看代码,或者“Alt+F11”键打开VBA编辑窗口。
在左侧对应的Sheet“All”上双击,弹出窗口空白处粘贴下面的代码。
Sub hb()
Dim bt, i, r, c, n, first As Long
bt = 1 '表头行数,多行改为对应数值
Cells.Clear
For i = 1 To Sheets.Count
If Sheets(i).Name <> ActiveSheet.Name Then
If first = 0 Then
c = Sheets(i).Cells(1, Columns.Count).End(xlToLeft).Column
Sheets(i).Range("A1").Resize(bt, c).Copy Range("A1")
n = bt + 1: first = 1
End If
r = Sheets(i).Cells(Rows.Count, "A").End(xlUp).Row
Sheets(i).Range("A" & bt + 1).Resize(r - 1, c).Copy Range("A" & n)
n = n + r - bt
End If
Next
End Sub
3
“F5”键或点击运行菜单,合并成功!