Thread: Array UDF
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
J.E. McGimpsey J.E. McGimpsey is offline
external usenet poster
 
Posts: 493
Default Array UDF

If you're creating a one dimensional array, you need to transpose it
if you're returning the values to a column. Here's one way:

Function rkArray(dataArray As Range, K As Integer) As Variant
Dim rk As Variant
Dim i As Long
ReDim rk(1 To K)
For i = 1 To UBound(rk)
rk(i) = dataArray.Cells(i).Value * i
Next i
With Application.Caller
If .Rows.Count = 1 Then
rkArray = rk
ElseIf .Columns.Count = 1 Then
rkArray = Application.Transpose(rk)
Else
rkArray = CVErr(xlErrNA)
End If
End With
End Function



In article ,
"Dileepan" wrote:

Hi,

I have an array UDF that displays value from the first
cell into all the cells in the array range. With MsgBox
I know the values are getting computed correctly. Please
let me know what I am doing wrong.

The relevant portion of the UDF is given below.

======================================
Function rkArray(dataArray As Range, K As Integer) As
Variant

.... statements .....

ReDim rk(K)

.... statements computing rk array

rkArray = rk
End Function
======================================

-- Dileepan