|
Sub 数据匹配()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
With Sheets("SIR")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a8:n" & r - 8)
f = Dir(lj & "1.xls*")
If f = "" Then MsgBox "找不到文件1": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 2).End(xlUp).Row
br = .Range("a8:g" & rs)
End With
wb.Close False
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" Then
d(Trim(br(i, 2))) = i
End If
Next i
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" Then
xh = d(Trim(ar(i, 2)))
If xh <> "" Then
ar(i, 5) = br(xh, 7)
ar(i, 14) = br(xh, 1)
End If
End If
Next i
Set f = Nothing
d.RemoveAll
f = Dir(lj & "*.xls*")
Do While f <> ""
If f <> ThisWorkbook.Name And f <> "1.xlsx" Then
Set wb = Workbooks.Open(lj & f, 0)
lh = Val(Split(wb.Name, ".")(0)) + 4
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 2).End(xlUp).Row
br = .Range("a8:g" & rs)
End With
wb.Close False
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
d(Trim(br(i, 1))) = i
End If
Next i
For i = 2 To UBound(ar)
If Trim(ar(i, 14)) <> "" Then
xh = d(Trim(ar(i, 14)))
If xh <> "" Then
ar(i, lh) = br(xh, 7)
End If
End If
Next i
End If
f = Dir
Loop
.Range("a8:n" & r - 8) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|