|
插入一个模块,贴粘代码。- Sub CommandButton1_Click()
- Dim strPath As String, strFile As String
- strPath = ThisWorkbook.Path & Application.PathSeparator & "数据文件" & Application.PathSeparator
- strFile = Dir(strPath & "*.xls")
- With Application
- .ScreenUpdating = False
- .DisplayAlerts = False
- .EnableEvents = False
- .Calculation = xlCalculationManual
- End With
- Do While Len(strFile)
- If strFile <> ThisWorkbook.Name Then
- Call Query(strPath & strFile)
- End If
- strFile = Dir
- Loop
- With Application
- .ScreenUpdating = True
- .DisplayAlerts = True
- .EnableEvents = True
- .Calculation = xlCalculationAutomatic
- End With
- MsgBox "汇总完成"
- Application.StatusBar = ""
- End Sub
- Sub Query(strFullname As String)
- Dim objwb As Workbook
- Dim objsh As Worksheet
- Dim objDst As Worksheet
- Dim arr, i&, j&
- Set objwb = GetObject(strFullname)
- Set objDst = ThisWorkbook.Worksheets("sheet0")
- Windows(objwb.Name).Visible = True
- Application.StatusBar = strFullname
- For Each objsh In objwb.Worksheets
- With objsh
- If .Name <> "Sheet0" Then
- arr = .Range(.Cells(1, 1), .Cells(.[a65536].End(3).Row, .[iv1].End(1).Column)).Value
- For i = 1 To UBound(arr)
- For j = i + 1 To UBound(arr)
- If arr(i, 4) = arr(j, 4) And arr(i, 10) = arr(j, 10) And arr(i, 11) = arr(j, 11) And arr(i, 13) = arr(j, 13) And arr(i, 14) = arr(j, 14) And arr(i, 16) = arr(j, 16) Then
- objDst.Cells([b65536].End(3).Row + 2, 1).Resize(, UBound(arr, 2)) = Application.Index(arr, i, 0)
- objDst.Cells([b65536].End(3).Row + 1, 1).Resize(, UBound(arr, 2)) = Application.Index(arr, j, 0)
- objDst.Cells([b65536].End(3).Row, 18) = Right(.Name, Len(.Name) - 5)
- End If
- Next j
- Next i
- End If
- End With
- Next objsh
- objwb.Close False
- End Sub
复制代码 |
|