|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
数据量大时,不适宜编辑事件,
可先复入品号,然后填上数量,再一次性引用其它项目及计算金额。
用数组处理会提高速度
(前堤是复入的品号在“价格表”是存在的)
各分表通用代码
Sub zz() ''条件引用与计算
Dim d, arr, brr, s$, t$, i, m
Set d = CreateObject("Scripting.Dictionary")
arr = Sheet2.UsedRange.Value
brr = ActiveSheet.UsedRange.Offset(1).Value
m = UBound(brr)
For i = 2 To UBound(arr)
d(arr(i, 3)) = Array(arr(i, 4), arr(i, 5), arr(i, 6), arr(i, 7))
Next
ReDim ar1(1 To m, 1 To 3)
ReDim ar2(1 To m, 1 To 2)
ReDim ar3(1 To m, 1 To 2)
For i = 1 To m
If brr(i, 7) <> "" Then
s = brr(i, 7)
ar1(i, 1) = d(s)(0)
ar1(i, 2) = d(s)(1)
ar1(i, 3) = d(s)(2)
ar2(i, 1) = d(s)(3)
ar2(i, 2) = ar2(i, 1) * brr(i, 5)
End If
If brr(i, 11) <> "" Then
t = brr(i, 11)
ar3(i, 1) = d(t)(3)
ar3(i, 2) = ar3(i, 1) * brr(i, 5)
End If
Next
[b2].Resize(m, 3) = ar1
[h2].Resize(m, 2) = ar2
[l2].Resize(m, 2) = ar3
Set d = Nothing
End Sub |
|