|
- Sub test()
- Dim r&, i&
- Dim arr, brr()
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With ThisWorkbook.Worksheets("sheet0")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:a" & r)
- x = arr(UBound(arr), 1)
- For i = 1 To UBound(arr)
- If arr(i, 1) = x Then
- d(i) = Empty
- End If
- Next
- End With
- mypath = ThisWorkbook.Path & ""
- myname = Dir(mypath & "*.xlsb")
- Do While myname <> ""
- Set wb = GetObject(mypath & myname)
- Windows(wb.Name).Visible = True
- With wb
- ReDim brr(1 To 10000, 1 To 2)
- m = 0
- With .Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 1 To UBound(arr, 2)
- For Each aa In d.keys
- If aa <= UBound(arr) Then
- If arr(aa, j) = x Then
- m = m + 1
- brr(m, 1) = aa
- brr(m, 2) = j
- End If
- End If
- Next
- Next
- End With
- With .Worksheets("sheet2")
- .Range("d1:e" & .Rows.Count).Clear
- If m > 0 Then
- .Range("d1").Resize(m, UBound(brr, 2)) = brr
- End If
- End With
- .Close True
- End With
- myname = Dir
- Loop
- End Sub
复制代码 |
|