Sub 合并()
Application.ScreenUpdating = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long, rs As Long
Dim br(), brr()
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "表1记录.xls*")
If f = "" Then MsgBox "找不到表1记录!": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("a1:bg" & r)
End With
wb.Close False
ReDim br(1 To UBound(ar), 1 To 18)
For i = 1 To UBound(ar)
If ar(i, 2) <> "" And ar(i, 7) <> "" Then
If IsDate(ar(i, 7)) Then
n = n + 1
br(n, 3) = ar(i, 2)
br(n, 4) = ar(i, 7)
br(n, 5) = ar(i, 15)
br(n, 7) = ar(i, 19)
br(n, 11) = ar(i, 55)
br(n, 18) = ar(i, 59)
End If
End If
Next i
If n = "" Then MsgBox "没有需要汇总的数据!": End
With ActiveSheet
.UsedRange.Offset(2) = Empty
.[a3].Resize(n, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|