Prb: Writing Array functions in VBA
You can't specify where a function returns its values - that depends on
where its called from.
As an example, if you had values in A1:A9, you could select B1:B9 and
array enter
=MyFunc(A1:A9)
Public Function MyFunc(rRange As Range) As Variant
Dim vTemp As Variant
Dim i As Long
Dim j As Long
With Application.Caller
If .Rows.Count = rRange.Rows.Count And _
.Columns.Count = rRange.Columns.Count Then
'Do something
ReDim vTemp(1 To rRange.Rows.Count, _
1 To rRange.Columns.Count)
For i = 1 To UBound(vTemp, 1)
For j = 1 To UBound(vTemp, 2)
vTemp(i, j) = rRange(i, j) * 2
Next j
Next i
MyFunc = vTemp
Else
MyFunc = CVErr(xlErrValue)
End If
End With
End Function
In article ,
neebington wrote:
I am trying to write an excel function in VBA that can has a 9 number
array as a variable and returns a 9 number array in the column to
variable array's right. I have been unable to find a way to write this
function properly. Any help (even just webpages with descriptions) is
greatly appreciated. Thanks
|