How to return array() in vba function to use it in cells Array formulas (matricial formula) : for split texte in multi cells

后端 未结 3 1360
故里飘歌
故里飘歌 2021-01-06 04:10

I\'m writing a function in VBA to use in excel formula, it\'s ok if my function return a single value:

=MYVALUE(A1)

Now I wrote another fu

3条回答
  •  青春惊慌失措
    2021-01-06 04:25

    A cell won't display an array, you would have to translate that array to a range/array of cells on the sheet. Alternatively, you could try converting the array to a delimited string, which may work as long as you aren't using very large arrays.

    Public Function MYARRAY(x As Integer)
    
    Dim tmpArray() As Variant
    Dim i As Long
    Dim arrayString As String
    
    tmpArray = Array(10, 20, 30)
    
    For i = LBound(tmpArray) To UBound(tmpArray)
        If arrayString = vbNullString Then
            arrayString = tmpArray(i)
        Else:
            arrayString = arrayString & ", " & tmpArray(i)
        End If
    Next
    
    MYARRAY = "{" & arrayString & "}"
    
    End Function
    

提交回复
热议问题