|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 匹配()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "查询采购合同明细.xls*")
If f = "" Then MsgBox "找不到查询采购合同明细文件": End
With ActiveSheet
ht = .Name
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "目标表为空!": End
.Range("g2:h" & rs) = Empty
ar = .Range("a1:h" & rs)
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:h" & r)
End With
wb.Close False
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
zf = ht & "|" & Trim(ar(i, 1))
zd = Trim(ar(i, 1))
dc(zd) = i
d(zf) = i
End If
Next i
For i = UBound(br) To 2 Step -1
If Trim(br(i, 4)) <> "" Then
zd = Trim(br(i, 1)) & "|" & Trim(br(i, 4))
xh = d(zd)
If xh <> "" Then
If ar(xh, 7) = "" Then
If InStr(br(i, 5), "拉伸膜") > 0 Then
ar(xh, 7) = br(i, 8) * 110
ElseIf InStr(br(i, 5), "气泡膜") > 0 Then
ar(xh, 7) = br(i, 8) * 180
Else
ar(xh, 7) = br(i, 8)
End If
ar(xh, 8) = ar(xh, 7) * ar(xh, 6)
End If
End If
End If
Next i
For i = UBound(br) To 2 Step -1
If Trim(br(i, 4)) <> "" Then
h = dc(Trim(br(i, 4)))
If h <> "" Then
If ar(h, 7) = "" Then
If InStr(br(i, 5), "拉伸膜") > 0 Then
ar(h, 7) = br(i, 8) * 110
ElseIf InStr(br(i, 5), "气泡膜") > 0 Then
ar(h, 7) = br(i, 8) * 180
Else
ar(h, 7) = br(i, 8)
End If
ar(h, 8) = ar(h, 7) * ar(h, 6)
End If
End If
End If
Next i
.Range("a1:h" & rs) = ar
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub |
|