|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("表1")
r1 = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:ae" & r1)
End With
With Sheets("表2")
r2 = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:ae" & r2)
End With
With Sheets("表3")
r3 = .Cells(Rows.Count, 1).End(xlUp).Row
If r3 < 12 Then MsgBox "表3为空!": End
.Range("ae12:ae" & r3) = Empty
cr = .Range("a11:ae" & r3)
For i = 2 To UBound(cr)
If Trim(cr(i, 1)) <> "" Then
d(Trim(cr(i, 1))) = i
End If
Next i
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
xh = d(Trim(ar(i, 1)))
If xh <> "" Then
cr(xh, 31) = cr(xh, 31) + ar(i, 31)
End If
End If
Next i
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
xh = d(Trim(br(i, 1)))
If xh <> "" Then
cr(xh, 31) = cr(xh, 31) - br(i, 31)
End If
End If
Next i
.Range("ae11:ae" & r3) = Application.Index(cr, 0, 31)
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|