|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
算是简化了一下代码把。
- Sub test()
- Dim arr, brr, crr, drr
- 'arr为入库数据,brr为退货数据,crr为出库数据,drr为商品信息目录数据
- Dim i%, dic, dic1, dic2
- Set dic = CreateObject("scripting.dictionary")
- Set dic1 = CreateObject("scripting.dictionary")
- Set dic2 = CreateObject("scripting.dictionary")
- arr = Sheets("入库").Range("a1").CurrentRegion
- brr = Sheets("退货").Range("a1").CurrentRegion
- crr = Sheets("出库").Range("a1").CurrentRegion
- drr = Sheets("商品信息目录").Range("a1").CurrentRegion
- For i = 2 To UBound(arr, 1)
- dic(arr(i, 2)) = dic(arr(i, 2)) + arr(i, 5)
- Next i
- For i = 2 To UBound(brr, 1)
- dic1(brr(i, 2)) = dic1(brr(i, 2)) + brr(i, 3)
- Next i
- For i = 2 To UBound(crr, 1)
- dic2(brr(i, 2)) = dic2(crr(i, 2)) + crr(i, 3)
- Next i
- For i = 2 To UBound(drr, 1)
- If dic.exists(drr(i, 3)) Then drr(i, 8) = dic(drr(i, 3))
- If dic1.exists(drr(i, 3)) Then drr(i, 9) = dic1(drr(i, 3))
- If dic2.exists(drr(i, 3)) Then drr(i, 10) = dic2(drr(i, 3))
- drr(i, 11) = drr(i, 7) + drr(i, 8) + drr(i, 9) - drr(i, 10)
- Next i
- Sheets("商品信息目录").Range("a1").Resize(UBound(drr), UBound(drr, 2)) = drr
-
-
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|