Transpose function not working on String Array

rkaczano

Board Regular
Joined
Jul 24, 2013
Messages
141
Office Version
  1. 365
Platform
  1. Windows
I am trying to transpose an array () as String using the Transpose function.

Application.WorksheetFunction.Transpose (DataArray)

This does not seem to be working as Debug.Print Ubound(DateArray,1) and Debug.Print Ubound(DateArray,2) before and after the transpose statement provide the same values indicating that the rows and columns have not been switched as as result of the transpose.

Does transpose not work on string arrays? And if so, do I need to convert the string array to a variant array? If so, how do I do that

Regards

RK
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It might help if you show us your code so we can see, at minimum, how you declared your array and how you assigned values to it.
 
Upvote 0
Sub Test1 did not work. I also tried a transpose function in Sub Test2 for transposing the string array. This worked by creating a new array as variant and having it equal the transpose of the first array.

***************
Sub Test1 ()
Dim DataArray() As String

'Load first array DataArray()
Lengthy code to pull data in from a text file into the array

Application.WorksheetFunction.Transpose (DataArray)

End Sub

********************
Sub Test2()
Dim DataArray() As String
Dim DataArray2() As Variant

'Load first array DataArray()
Lengthy code to pull data in from a text file into the array

DataArray2 = TransposeArray(DataArray)

End Sub


VBA Code:
Public Function TransposeArray(myarray As Variant) As Variant
Dim X As Long
Dim Y As Long
Dim Xupper As Long
Dim Yupper As Long
Dim tempArray As Variant
    Xupper = UBound(myarray, 2)
    Yupper = UBound(myarray, 1)
    ReDim tempArray(Xupper, Yupper)
    For X = 0 To Xupper
        For Y = 0 To Yupper
            tempArray(X, Y) = myarray(Y, X)
        Next Y
    Next X
    TransposeArray = tempArray
End Function
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top