|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 物料用途整理()
Dim nR1%, nL1%, nR2&, nR%, nL%, nJe, Arr(), Brr()
Dim ds As Object
Set ds = CreateObject("Scripting.Dictionary") '创建字典
With Sheets("目标表")
nR1 = .Range("b4").End(xlDown).Row
nL1 = .Range("b4").End(xlToRight).Column
.Range(.Range("d6"), .Cells(nR1, nL1)).ClearContents
Arr = .Range(.Range("b4"), .Cells(nR1, nL1)).Value
End With
With Sheets("数据源表")
nR2 = .Range("a3").End(xlDown).Row
Brr = .Range("b4:e" & nR2).Value
End With
For i = 4 To nL1 - 1
ds(Arr(2, i)) = i
Next
For i = 4 To nR1 - 3
ds(Arr(i, 1) & Arr(i, 2)) = i
Next
For i = 1 To nR2 - 3
nJe = Brr(i, 4)
nL = ds(Left(Brr(i, 3), 4))
nR = ds(Brr(i, 1) & Brr(i, 2))
If nL * nR * nJe <> 0 Then
Arr(3, 3) = Arr(3, 3) + nJe
Arr(3, nL) = Arr(3, nL) + nJe
Arr(nR, nL) = Arr(nR, nL) + nJe
Arr(nR, 3) = Arr(nR, 3) + nJe
nR = ds(Brr(i, 1) & "合计")
If nR > 0 Then
Arr(nR, nL) = Arr(nR, nL) + nJe
Arr(nR, 3) = Arr(nR, 3) + nJe
End If
End If
Next
With Sheets("目标表")
.Range(.Range("b4"), .Cells(nR1, nL1)).Value = Arr
End With
End Sub
|
|