[算表] VBA如何将阵列转为range

楼主: nazomegami (深呼吸~)   2016-03-15 22:00:26
软件: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
作者: soyoso (我是耀宗)   2016-03-15 23:10:00
用evaluate试试
楼主: nazomegami (深呼吸~)   2016-03-16 09:09:00
我令变量a=Evaluate("{""" & Join(ary2, """;""") & """}")并将sumif函数中的ary2以a变量来取代但还是失败了但是a有成功转变为与amount一样的格式
作者: soyoso (我是耀宗)   2016-03-16 11:06:00
想到的是用evaluate用于sumif上因带入function为range型态是否改用sumifs的方式加总
楼主: nazomegami (深呼吸~)   2016-03-16 17:56:00
可能要用evaluate(sum(if...的方式我再试试
作者: soyoso (我是耀宗)   2016-03-16 18:36:00
抱歉是用于sum(if上,如原po先前VBA阵列运算问题(SUMIF)的回文方式
楼主: nazomegami (深呼吸~)   2016-03-17 17:05:00
已测试成功,谢谢!

Links booklink

Contact Us: admin [ a t ] ucptt.com