|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 匹配()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("核算项目表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r < 3 Or y < 3 Then MsgBox "核算项目表为空!": End
ar = .Range(.Cells(2, 1), .Cells(r, y))
End With
For j = 3 To y Step 2
If Trim(ar(1, j)) <> "" Then
For i = 2 To UBound(ar)
If Trim(ar(i, j - 1)) <> "" Then
zd = Trim(ar(1, j)) & "|" & Trim(ar(i, j - 1))
d(zd) = ar(i, j)
End If
Next i
End If
Next j
With Sheets("科目汇总表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 7 Then MsgBox "科目汇总表为空!": End
.Range("d7:e" & rs) = Empty
br = .Range(.Cells(5, 1), .Cells(rs, 11))
For i = 3 To UBound(br)
If Trim(br(i, 1)) <> "" And Trim(br(i, 2)) <> "" Then
zd = Trim(br(i, 1)) & "|" & Trim(br(i, 2))
If d.exists(zd) Then
If Trim(br(i, 11)) = "借" Then
br(i, 4) = d(zd)
Else
br(i, 5) = d(zd)
End If
End If
End If
Next i
.[d5].Resize(UBound(br), 1) = Application.Index(br, 0, 4)
.[e5].Resize(UBound(br), 1) = Application.Index(br, 0, 5)
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|