Excel – MACRO GỘP DỮ LIỆU NHIỀU SHEETS EXCEL VÀO 1 SHEET

Tạo sheet Tong hop.

Insert module

Copy code sau vào trong module mới vừa tạo ra:

Sub MergeSheets()
Dim x As Integer
Dim ws As Worksheet

On Error GoTo ErrHandler
Application.ScreenUpdating = False

x = 1
For Each ws In ThisWorkbook.Sheets
If ws.Name <> “Tong Hop” Then
If x = 1 Then
ws.UsedRange.Copy Sheets(“Tong Hop”).Range(“A1”)
Else
lr = Sheets(“Tong Hop”).UsedRange.Rows.Count
ws.UsedRange.Offset(1).Copy Sheets(“Tong Hop”).Range(“A” & lr + 1)
End If
x = x + 1
End If
Next ws

ErrHandler:
Debug.Print Err.Description
End Sub

 

Advertisements