VBA-Excel return multidimensional array from a function

Posted by alesdario on Stack Overflow See other posts from Stack Overflow or by alesdario
Published on 2012-10-30T12:12:16Z Indexed on 2012/10/30 17:01 UTC
Read the original article Hit count: 196

I'm trying to write a function which returns a multidimensional array. The problem is that the size of the array isn't defined.

My array is initialized in the function below my_list()

Dim my_list() As String

Public Sub Load_My_List()

    Dim last_column As Integer
    last_column = some_helper.Get_Last_Column(somw_worksheet)

    'my array is resized in this point
    ReDim my_list(1 To last_column - 1, 1)

    Dim i As Integer
    i = 1

    For index= 2 To ultima_colonna


       my_list(i, 0) = some_worksheet.Cells(2, index).value
       my_list(i, 1) = index

       i = i + 1

    Next index

End Sub

So, how can i write a function which returns my_list ? Something like the function below generate a mismacthing type error

Public function Get_My_List as String()

    Get_My_List = my_list 

End Function

and how can i call this function properly? I think that something like

Dim test() as String
test = Get_My_List

will doesn't work

© Stack Overflow or respective owner

Related posts about function

Related posts about excel-vba