|
Option Explicit
Sub TEST()
Dim ar, br, i&, j&, r&, dic As Object, wks As Worksheet, iPosCol&, vKey
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
.Offset(2).ClearContents
ar = .Resize(10 ^ 3)
End With
r = 2
For i = 2 To UBound(ar, 2): dic(ar(2, i)) = i: Next
For Each wks In Sheets
If wks.Name <> ActiveSheet.Name Then
With wks
br = .[A3].CurrentRegion
For i = 2 To UBound(br)
If br(i, 1) = [B1] Then
r = r + 1
ar(r, 1) = .[A1]
For j = 1 To UBound(br, 2)
vKey = br(1, j)
If dic.exists(vKey) Then
iPosCol = dic(vKey)
ar(r, iPosCol) = br(i, j)
End If
Next j
End If
Next i
End With
End If
Next
Set dic = Nothing
[A1].Resize(r, UBound(ar, 2)) = ar
Application.ScreenUpdating = True
Beep
End Sub
|
|