[置顶] 【excel VBA】合并当前工作薄下多个sheet表

时间:2022-08-26 09:29:36

程序1

Sub 合并当前工作簿下的所有工作表()
Application.ScreenUpdating = False
For j = 1 To Sheets.Count
If Sheets(j).Name <> ActiveSheet.Name Then
X = Range("A65536").End(xlUp).Row + 1
Sheets(j).UsedRange.Copy Cells(X, 1)
End If
Next
Range("B1").Select
Application.ScreenUpdating = True
MsgBox "当前工作簿下的全部工作表已经合并完毕!", vbInformation, "提示"
End Sub

程序2

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Rows("2:1048576").Clear
Dim xrow As Integer, sht As Worksheet, rng As Range
For Each sht In Worksheets
If sht.Name <> ActiveSheet.Name Then
Set rng = Range("C1048576").End(xlUp).Offset(1, -1)
sht.AutoFilterMode = False
xrow = sht.UsedRange.Rows.Count - 1
sht.Range("B2").Resize(xrow, 6).Copy rng
sht.Rows("1:1").AutoFilter
End If
Next
Application.ScreenUpdating = True
MsgBox "当前工作簿下的全部工作表已经合并完毕!", vbInformation, "提示"
End Sub