0
我有一個函數,我想創建一個數組,但它不允許我在函數內部ReDim數組。VBA函數中的ReDim無效
Function engArray(rigStck As Variant) As Variant
'CREATE ENGINE ARRAY WITH #, USAGE DAYS AND USED?
If rigStck <> 0 Then
ReDim engArray(1 To rigStck, 2)
For n = 1 To UBound(engArray)
'engine numbering
engArray(n, 0) = n
'reset engine usage to 0
engArray(n, 1) = 0
engArray(n, 2) = 0
Next
Else
engArray(1, 0) = 0
End If
End Function
使用一個臨時數組'暗淡TmpArray()作爲variant'然後REDIM臨時數組你想要的大小。然後在結尾'engarray = TmpArray' –
完美。乾杯! – peetman
正如Scott提供的解決方案,原因是你的函數本身不是一個數組本身,它可以是redim – MatthewD