|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 匹配()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "计划日期.xlsx")
If f = "" Then MsgBox "找不到计划日期文件": End
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:b" & rs)
End With
wb.Close False
With Sheets("sheet1")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "目标表为空!": End
.Range("b2:b" & r) = Empty
ar = .Range("a1:b" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
rq = "2095/1/1"
For s = 2 To UBound(br)
If Trim(br(s, 1)) = Trim(ar(i, 1)) Then
If br(s, 2) <= rq Then
rq = br(s, 2)
End If
End If
Next s
If rq <> "2095/1/1" Then ar(i, 2) = rq
End If
Next i
.Range("a1:b" & r) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|