UDF, Array function, vertical output

  • Thread starter Thread starter Robin Hammond
  • Start date Start date
R

Robin Hammond

This is probably a simple answer. I have a UDF that retrieves stock prices
from a database. The return values should obviously be laid out vertically.
The UDF is returning the correct values when entered horizontally, but will
only give the correct answers when I use Transpose(UDF) in a vertical
format.

Am I missing something here? Is there a way to get an array based UDF to
work with vertical output without having to use the transpose function?

Thanks,

Robin Hammond
www.enhanceddatasystems.com
 
You can do the transpose inside the VBA, i.e.

Function GetPrices() As Variant
Dim V as Variant

'code here to load V with your array of prices here

GetPrices = Application.Transpose(V)
End Function

Or, depending on how the prices are returned from the database, you could Dim
and fill your own array:

Function GetPrices() As Double()
Dim i As Long
Dim Prices() As Double

ReDim Prices(1 To 3, 1 To 1)
For i = 1 To 3
Prices(i, 1) = Round(Rnd() * 50, 3)
Next i
GetPrices = Prices()
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top