Output VBA Array Elements to One Cell in Excel

牧云@^-^@ 提交于 2019-12-02 13:31:50

问题


So i have a vba code that creates an array with multiple elements. I would like to output those elements into one cell in excel. Im able to output its elements to multiple cells but prefer it in one cell. Can this be done?


回答1:


If the array is declared as a String or Variant then you can use Join:

Sub AllIntoOne()
    Dim arr(1 To 3) As Variant
    arr(1) = 4
    arr(2) = 54
    arr(3) = 3
    Range("A1") = Join(arr, ",")

End Sub

The delimiter "," defaults to a space if not supplied, but can be an empty string "" if no separation is required.



来源:https://stackoverflow.com/questions/18543517/output-vba-array-elements-to-one-cell-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!