我有一個函數,它接受一個數組並輸出另一個數組。其內部比下面的玩具例子更復雜。接受範圍作爲數組參數
Public Function divide_by_2_5(ByRef coeffs() As Double) As Double()
Dim Columns As Integer
Columns = UBound(coeffs, 2) - LBound(coeffs, 2) + 1
Dim output() As Double
ReDim output(1 To 1, 1 To Columns)
Dim i As Integer
For i = 1 To Columns
output(1, i) = coeffs(1, i)/2.5
Next i
divide_by_2_5 = output
End Function
這是我看到:
我想在第二排,而不是包含函數的輸出。在這種情況下,那將是0.4, 0.4, 0.4, 0.4
。
不幸的是,我得到一個#VALUE!
錯誤,我不知道如何調試。
一些澄清:顯然有可能有相同的函數返回一個數組或寫入電子表格(與Ctrl
- Shift
- Enter
)。以類似的方式,輸入是來自範圍還是數組?
如果您想要將一系列單元格傳遞給該函數,則需要將傳遞的參數聲明爲Range或Variant。 – YowE3K
您的'ReDim輸出(1,coeffs)'語句應該是'ReDim output(1,columns)'。 – YowE3K
@ YowE3K,謝謝,編輯 – user357269