Sub TongHop2() Dim objFSO As Object, objFolder As Object, ObjFile As Object, rsCon As Object, rsData As Object
Dim szConnect, szSQL, SourceFile, SourceSheet, SourceRange As String
Dim Darr(), Arr, Ro, R, i As Integer, j As Integer, k As Integer, n As Integer, SoDong As Integer, S As Integer
SoDong = 2
ReDim Darr(0 To SoDong - 1, 0 To 1146)
'Ro = Array(0, 7, 11, 15, 22, 27)
'0,7,11 ...là dòng dau cua tung vùng láy du lieu, dem tu so 0 cua dong dau tien(dong 13 cua sheet là: 0)
Ro = Array(0, 120, 423, 547, 574, 591, 608, 627, 639, 656, 675, 682, 689, 700, 1020, 1028, 1040, 1101, 1114, 1125, 1129, 1133)
R = Array(13, 133, 436, 560, 587, 604, 621, 640, 652, 669, 688, 695, 702, 713, 1033, 1041, 1053, 1114, 1127, 1138, 1142, 1146)
'R = Array(13, 38, 59, 80, 104, 126)
'13,38...là dòng dau cua tung vùng tra ket qua
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(ThisWorkbook.Path)
For Each ObjFile In objFolder.Files
If Right(ObjFile, Len(ThisWorkbook.Name)) <> ThisWorkbook.Name Then
SourceFile = ObjFile: SourceSheet = "Sheet1": SourceRange = "B13:AU1143"
If Application.Version < 12 Then
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & SourceFile & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
Else
szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & SourceFile & ";" & "Extended Properties=""Excel 12.0;HDR=No"";"
End If
szSQL = "SELECT * FROM [" & SourceSheet & "$" & SourceRange$ & "] "
Set rsCon = CreateObject("ADODB.Connection")
Set rsData = CreateObject("ADODB.Recordset")
rsCon.Open szConnect
rsData.Open szSQL, rsCon, 3, 1
If Not rsData.EOF Then Arr = rsData.GetRows()
rsData.Close: Set rsData = Nothing
rsCon.Close: Set rsCon = Nothing
n = n + 1
For k = 0 To 5
For j = 0 To 1146
For S = 0 To SoDong - 1
Darr(S, j) = Arr(j, Ro(k) + S)
Next S
'Darr(0, j) = Arr(j, Ro(k))
'Darr(1, j) = Arr(j, Ro(k) + 1)
Next j
ThisWorkbook.Sheets("TONGHOP").Range("B" & R(k) + (n - 1) * SoDong).Resize(SoDong, 1147) = Darr
Next k
End If
Next ObjFile
Set objFSO = Nothing: Set objFolder = Nothing: Set ObjFile = Nothing
Application.ScreenUpdating = True
End Sub