Copy Many Sheet in Different Files To One Sheet

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

'Copy many sheet in different files to one sheet'

Sub copyandmergefilesinonesheet()

Dim chonFile As Variant

Dim i As Integer

Dim openfile As Workbook

Dim lastrow As Double

ThisWorkbook.Sheets(2).Range("B:S").Delete 'Xoa du lieu cu

Application.ScreenUpdating = False 'Tranh man hinh nhap nhay khi mo file

'Chon file la bin de tro den cac file duoc chon

chonFile = Application.GetOpenFilename(Title:="Chon cac file can copy", filefilter:="Excel file(*.xls*),


*xls*", MultiSelect:=True)

For i = 1 To UBound(chonFile) 'Mo tung file 1 tu file dau tien den file cuoi cung

lastrow = ThisWorkbook.Sheets(2).Range("B" & ThisWorkbook.Sheets(2).Rows.Count).End(x1Up).Row '


Tinh hang cuoi cung

openfile.Sheets(1).Range("B2").CurrentRegion.Copy 'Paste du lieu duoi dang value

ThisWorkbook.Sheets(2).Range("B" & lastrow + 1).Pastespecialx1pastvalues

If i > 1 Then

This Workbook.Sheets(2).Rows(lastrow + 1).Delete ' xoa cac cot tieu de tu file thu hai tro di

End If

openfile.Close False ' Dong file bang VBA

Next

End Sub

You might also like