ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function that return a a vector or a table (https://www.excelbanter.com/excel-programming/347512-function-return-vector-table.html)

Jean-Pierre Bidon

Function that return a a vector or a table
 
Hi,
Is it possible for a function to return an array...and how?
Any help would be appreciated.
Thank you
Jean-Pierre Bidon



Dave Peterson

Function that return a a vector or a table
 
Yep. You can have the array returned to that single cell or to a range of
cells.

Option Explicit
Function testme() As Variant

Dim iCtr As Long
Dim myArr(1 To 10) As String

For iCtr = 1 To 10
myArr(iCtr) = "test" & iCtr
Next iCtr

testme = Application.Transpose(myArr)

End Function

Select A1:A10, type =testme() and hit ctrl-shift-enter.

Jean-Pierre Bidon wrote:

Hi,
Is it possible for a function to return an array...and how?
Any help would be appreciated.
Thank you
Jean-Pierre Bidon


--

Dave Peterson

Jean-Pierre Bidon

Function that return a a vector or a table
 
I tried your solution and it works.
Thank you Dave.
Jean-Pierre

"Dave Peterson" a écrit dans le message de news:
...
Yep. You can have the array returned to that single cell or to a range of
cells.

Option Explicit
Function testme() As Variant

Dim iCtr As Long
Dim myArr(1 To 10) As String

For iCtr = 1 To 10
myArr(iCtr) = "test" & iCtr
Next iCtr

testme = Application.Transpose(myArr)

End Function

Select A1:A10, type =testme() and hit ctrl-shift-enter.

Jean-Pierre Bidon wrote:

Hi,
Is it possible for a function to return an array...and how?
Any help would be appreciated.
Thank you
Jean-Pierre Bidon


--

Dave Peterson





All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com