[英]EXCEL VBA - Function that retrun array
I want to build function in VBA that build an array and return it to array that's in another sub so I can use this function in multiple places.我想在 VBA 中构建 function 构建一个数组并将其返回到另一个子中的数组,这样我就可以在多个地方使用这个 function。 For example:例如:
Sub getArrayData ()
Dim myItemsArr() As String ' dynamic array
myItemsArr = functionToFillArray
End sub
And let's assume this is the function让我们假设这是 function
Function functionToFillArray(arrayIWantToFill as Variant)
arrayToFill = ("A","B","C")
arrayIWantToFill = ???
functionToFillArray = ?? ' what should i do here to return the array i want to fill
End function
At other language suck as Java its more clear to me how to do it, but in VBA I just don't understand how its work yet.在其他语言中,Java 对我来说更清楚如何做到这一点,但在 VBA 中,我只是不明白它是如何工作的。 I try to find some information online, but without success我尝试在网上查找一些信息,但没有成功
Like this:像这样:
Function getArrayData() As Variant
Dim myItemsArr As Variant
' Fill array.
functionToFillArray myItemsArr
getArrayData = myItemsArr
End Function
Sub functionToFillArray(arrayIWantToFill As Variant)
arrayIWantToFill = Array("A","B","C")
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.