|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim Items As FileDialogSelectedItems, strPath$
Dim ar, br, i&, j&, r&, dic As Object, vKey, vItem
strPath = ThisWorkbook.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "Excel Files", "*.xlsx"
End With
.AllowMultiSelect = True
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With [A1].CurrentRegion
r = .Rows.Count
ar = .Resize(1000)
End With
For i = 2 To UBound(ar, 2)
If (ar(1, i)) = "" Then ar(1, i) = ar(1, i - 1)
vKey = ar(1, i) & ar(2, i)
dic(vKey) = i
Next i
For Each vItem In Items
With GetObject(vItem)
br = .Sheets(2).[B2].CurrentRegion
r = r + 1
For i = 3 To UBound(br)
ar(r, 1) = br(1, 1)
For j = 2 To UBound(br, 2)
vKey = br(i, 1) & br(2, j)
If dic.exists(vKey) Then
ar(r, dic(vKey)) = br(i, j)
End If
Next j
Next i
.Close False
End With
Next
Columns(1).NumberFormatLocal = "yyyy-mm-dd"
[A1].Resize(UBound(ar), UBound(ar, 2)) = ar
Set Items = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|