|
把数据表整理一下,不能有合并单元格,然后用下面的代码:
Option Explicit
Sub test()
Dim myPath$, MyName$, sh As Worksheet, t#
Dim Arr, brr, i&, j&, m&, n&
t = Timer
myPath = ThisWorkbook.Path & "\"
MyName = Dir(myPath & "*.xls")
Application.ScreenUpdating = False
ReDim brr(1 To 100000, 1 To 9)
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
n = n + 1
Set sh = GetObject(myPath & MyName).Sheets("Sheet1")
Arr = sh.[A1].CurrentRegion
Workbooks(MyName).Close False
For i = 3 To UBound(Arr)
If Arr(i, 8) Like "农民工*" Then
m = m + 1
For j = 1 To 9
brr(m, j) = Arr(i, j)
Next
End If
Next
End If
MyName = Dir
Loop
Set sh = Nothing
With Sheet1
.Rows("1:3000").ClearContents
.[A1].Resize(2, UBound(Arr, 2)).Value = Arr
.[a3].Resize(m, UBound(brr, 2)).Value = brr
End With
Application.ScreenUpdating = True
MsgBox "汇总完成!汇总了:" & n & "个工作表;共有:" & m & "行数据。" & vbCr & "用时:" & Format(Timer - t, "0.00") & "秒", vbInformation
End Sub |
|