如何在 VBA 函数中将多范围作为参数传递?
How to pass multirange in VBA functions as parameter?
Public Function iQuery(pName As Varient, pTime As Varient)
For Each item in pName
...
Next item
End Function
我有一个名为 iQuery 的函数,我想传递范围 $A,$A,$A,$A
作为 pName 和范围 $A
作为 pTime 但它选择 $A
作为 pName 和 $A
作为pTime当iQuery被调用为iQuery($A,$A,$A,$A,$A)
如果您从 VBA 执行此操作,则需要将范围作为范围对象传递。看这个例子
Sub Sample()
Dim rngA As Range
Dim rngB As Range
Dim Ret As ??????
Set rngA = Range("$A,$A,$A,$A")
Set rngB = Range("$A")
Ret = iQuery(rngA, rngB)
End Sub
Public Function iQuery(pName As Range, pTime As Range) As ??????
Dim itm As Range
For Each itm In pName
...
Next itm
End Sub
其中 ??????
是您想要 return 的相关数据类型。
如果您是通过工作表执行此操作,则将其作为一个范围传递。例如
=iQuery($A:$A,$A)
But What if sFormula is "=iQuery($A,$B,$C,$A,$A)" and I want first parameter to be $A,$B,$C,$A and second one $A – rs4 18 mins ago
对于非连续范围,使用括号。例如
=iQuery(($A,$B,$C,$A),$A)
Public Function iQuery(pName As Varient, pTime As Varient)
For Each item in pName
...
Next item
End Function
我有一个名为 iQuery 的函数,我想传递范围 $A,$A,$A,$A
作为 pName 和范围 $A
作为 pTime 但它选择 $A
作为 pName 和 $A
作为pTime当iQuery被调用为iQuery($A,$A,$A,$A,$A)
如果您从 VBA 执行此操作,则需要将范围作为范围对象传递。看这个例子
Sub Sample()
Dim rngA As Range
Dim rngB As Range
Dim Ret As ??????
Set rngA = Range("$A,$A,$A,$A")
Set rngB = Range("$A")
Ret = iQuery(rngA, rngB)
End Sub
Public Function iQuery(pName As Range, pTime As Range) As ??????
Dim itm As Range
For Each itm In pName
...
Next itm
End Sub
其中 ??????
是您想要 return 的相关数据类型。
如果您是通过工作表执行此操作,则将其作为一个范围传递。例如
=iQuery($A:$A,$A)
But What if sFormula is "=iQuery($A,$B,$C,$A,$A)" and I want first parameter to be $A,$B,$C,$A and second one $A – rs4 18 mins ago
对于非连续范围,使用括号。例如
=iQuery(($A,$B,$C,$A),$A)