软件:excel vba
版本:2010
各位版大好,以下我有一个自订函数,其中ary2(i,0)为不同字串之组合(projectx、numx
等),我想要在一个循环里使用sumif,但是在这里ary2参数似乎是要为range型态,我不想
要在储存格中多一栏来记录此一组合字串。
不知道这样的问题是否有解法? 谢谢!!
Function inventory_period(in_date As Range, cur_date As Range, _
project As Range, num As Range, srl As Range, _
item_name As Range, amount As Range) As Long
Dim in_datex, cur_datex, projectx, numx, srlx, item_namex, amountx, str1
Dim ary1$(), ary2(10, 1), ary3(10)
Dim i&, w&
in_datex = in_date
cur_datex = cur_date
projectx = project
numx = num
srlx = srl
item_namex = item_name
amountx = amount
For i = 1 To UBound(projectx)
ary2(i, 0) = projectx(i, 1) & numx(i, 1) & srlx(i, 1) & item_namex(i, _
1)
ary2(i, 1) = cur_datex - in_datex(i, 1)
Next
For i = 1 To UBound(projectx)
If InStr(str1, ary2(i, 0)) = 0 Then
w = w + 1
str1 = str1 & "," & ary2(i, 0)
ary3(w) = WorksheetFunction.SumIf(ary2, ary2(i, 0), amount)
End If
Next
End Function