|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 匹配()
Dim ar As Variant
Dim sh As Worksheet, sht As Worksheet
Dim d As Object, dc As Object
Dim arr()
Dim ws
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
ReDim arr(1 To Sheets.Count)
With Sheets("包材计划")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 2 Then MsgBox "包材计划为空!": End
ar = .Range("a1:l" & r)
End With
With Sheets("sheet2")
rs = .Cells(Rows.Count, 5).End(xlUp).Row
If rs < 2 Then MsgBox "sheet2为空!": End
y = .Cells(1, Columns.Count).End(xlToLeft).Column
.Range(.Cells(2, 8), .Cells(rs, y)) = Empty
br = .Range(.Cells(1, 1), .Cells(rs, y))
For i = 2 To UBound(br)
If Trim(br(i, 5)) <> "" Then
d(Trim(br(i, 5))) = i
End If
Next i
For j = 8 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) <> "" And Trim(ar(i, 9)) <> "" Then
xh = d(Trim(ar(i, 9)))
lh = d(Trim(ar(i, 2)))
If xh <> "" And lh <> "" Then
br(xh, lh) = ar(i, 12)
End If
End If
Next i
.Range(.Cells(1, 1), .Cells(rs, y)) = br
End With
MsgBox "ok!"
End Sub
|
|