问题
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