|
Sub test()
Application.ScreenUpdating = False
Dim r%, i%, c%, j%
Dim arr, brr
Dim d As Object
Set d = CreateObject("scripting.dictionary")
ReDim arr(1 To 10000, 1 To 3)
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "*.xls*")
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
c = .Cells(1, .Columns.Count).End(xlToLeft).Column
x = .UsedRange.Rows.Count
ar = .Range("a1").Resize(x, c)
End With
wb.Close False
For i = 2 To UBound(ar)
For j = 14 To UBound(ar, 2)
If InStr(ar(1, j), "批号") > 0 Then
If Trim(ar(i, j)) <> "" Then
'If Len(Trim(ar(i, j))) = 10 Then
t = d(Trim(ar(i, j)))
If t = "" Then
k = k + 1
d(Trim(ar(i, j))) = k
t = k
arr(k, 1) = ar(i, j)
arr(k, 2) = ar(i, j - 1)
End If
arr(t, 3) = arr(t, 3) + ar(i, j + 1)
'End If
End If
End If
Next j
Next i
End If
f = Dir
Loop
'If k = "" Then End
With ActiveSheet
.[a1].CurrentRegion.Offset(1) = Empty
.[a2].Resize(k, 3) = arr
End With
Application.ScreenUpdating = True
End Sub
|
|