返回一个变量大小结果数组的方法
此方法返回基于一个参数范围的值的数组。结果数组的大小具体取决于参数数组中的元素数量波动。例如对于假定您要创建一个范围中的每个值乘以 100 的函数。下面的自定义函数接受作为其参数的数组 (某一范围的值):
Function Multiply_Range(myrange As Object) As Variant Dim temp As Variant Dim i As Integer, j As Integer temp = myrange.Value 'creates a copy of the values in myrange ' if more than one element then loop through both dimensions of ' the array and multiply each element by 100. ' if not more than one element then temp is multiplied by 100. If IsArray(temp) Then For i = 1 To UBound(temp, 1) For j = 1 To UBound(temp, 2) temp(i, j) = temp(i, j) * 100 Next j Next i Else temp = temp * 100 End If