|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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
|
|