Sub Copydulieu()
Dim shOutput As Worksheet, wbInput As Workbook
Dim selectfiles As Variant
Dim iFileNum, isheetNum, i As Integer
Dim ilastRowInput, ilastRowOutput As Long
Dim tieude As Boolean, RngAddress As String, Rng As Range
RngAddress = ThisWorkbook.Sheets(1).Cells(7, 4).Value
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'TAO MOT FILE LUU DATA
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & "Ket qua" & ".xlsx"
Set shOutput = ActiveWorkbook.Sheets(1)
'Goi phuwowng thuc mo nhieu file
selectfiles = Application.GetOpenFilename(Filefilter:="Excel File (*.xls*),*.xlsx", MultiSelect:=True)
For iFileNum = 1 To UBound(selectfiles)
Set wbInput = Workbooks.Open(selectfiles(iFileNum))
With wbInput.Sheets("EWF")
If .Range(RngAddress) <> "" Then
'Xac dinh dong cuoi cung, de copy du lieu tiep theo
ilastRowInput = .Range(Mid(RngAddress, 1, 1) & Rows.Count).End(xlUp).Row
'Copy vung tieu de
If tieude = False Then
ilastRowOutput = shOutput.Range(Mid(RngAddress, 1, 1) & Rows.Count).End(xlUp).Row
.Range(RngAddress).Copy Destination:=shOutput.Range(Mid(RngAddress, 1, 1) & ilastRowOutput + 1)
tieude = True
End If
ilastRowOutput = shOutput.Range(Mid(RngAddress, 1, 1) & Rows.Count).End(xlUp).Row
Set Rng = .Range(Mid(Range(RngAddress).Offset(1).Address(0, 0), 1, 4) & ilastRowInput)
Rng.Copy Destination:=shOutput.Range(Mid(RngAddress, 1, 1) & ilastRowOutput + 1)
shOutput.Range(Mid(RngAddress, 1, 1) & ilastRowOutput + 1).Resize(Rng.Rows.Count, Rng.Columns.Count).Value = _
shOutput.Range(Mid(RngAddress, 1, 1) & ilastRowOutput + 1).Resize(Rng.Rows.Count, Rng.Columns.Count).Value
End If
End With
wbInput.Close
Next
MsgBox "DA COPY XONG"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub