VBA manual transpose

限于喜欢 提交于 2019-12-11 17:39:06

问题


So I have noticed that Application.transpose doesnt take more than 255 characters and my array contain more than 300 characters or so. Is there a manual or another way to transpose an array? Currently I use

Function Transpose(arrIn) As String()
    Dim arrOut() As String, r As Long, ln As Long, i As Long

    ln = (UBound(arrIn) - LBound(arrIn)) + 1
    ReDim arrOut(1 To ln, 1 To 1)
    i = 1
    For r = LBound(arrIn) To UBound(arrIn)
        arrOut(i, 1) = arrIn(r)
        i = i + 1
    Next r
    Transpose = arrOut

End Function

But I have noticed that this only takes a 1D array and transposes it, but I must be able to go from 1D to 2D and vise verse. Anyone who knows how to do this in a efficient way?

Updated: This is what I currently use, but I think it needs some improvements.

Function Transpose1(arrIn) As String()
    Dim arrOut() As String, r As Long, ln As Long, i As Long

    ln = (UBound(arrIn) - LBound(arrIn)) + 1
    ReDim arrOut(1 To ln)
    i = 1
    For r = LBound(arrIn) To UBound(arrIn)
        arrOut(i) = arrIn(r, UBound(arrIn, 2))
        i = i + 1
    Next r
    Transpose1 = arrOut

End Function


' From one 2 two
Function Transpose2(arrIn) As String()
    Dim arrOut() As String, r As Long, ln As Long, i As Long

    ln = (UBound(arrIn) - LBound(arrIn)) + 1
    ReDim arrOut(1 To ln, 1 To 1)
    i = 1
    For r = LBound(arrIn) To UBound(arrIn)
        arrOut(i, 1) = arrIn(r)
        i = i + 1
    Next r
    Transpose2 = arrOut

End Function

来源:https://stackoverflow.com/questions/51174829/vba-manual-transpose

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