VBA - How to Transpose a 2 dimensional array?

bomvoo

New Member
Joined
Nov 16, 2004
Messages
42
Does anybody know a quick way to transpose a 2 dimensional array?

Below is an example of the problem:

Code:
dim T(1 TO 3, 1 TO 2) as double
dim TT(1 TO 2, 1 TO 3) as double

T(1,1)=1.6
T(1,2)=1.5
T(2,1)=2.4
T(2,2)=2.6
T(3,1)=0.2
T(3,2)=0.5

'The question is if anybody knows a function like this:
TT= transpose(T)

'Such that
'TT(1,1)=1.6  (T(1,1))
'TT(1,2)=2.4  (T(2,1))
'TT(1,3)=0.2  (T(3,1))
'TT(2,1)=1.5  (T(1,2))
'TT(2,2)=2.6  (T(2,2))
'TT(2,3)=0.5  (T(3,2))



end sub


Thank you in advance
Regards,
Eduardo
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,915
Office Version
  1. 365
Platform
  1. Windows
Try this.
Code:
Dim T(1 To 3, 1 To 2) As Double
Dim TT

T(1, 1) = 1.6
T(1, 2) = 1.5
T(2, 1) = 2.4
T(2, 2) = 2.6
T(3, 1) = 0.2
T(3, 2) = 0.5

TT = Application.WorksheetFunction.Transpose(T)
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Eduardo

You can do this using Application.Worksheetfunction.Transpose, but I think you may have to use a variant variable when you are assigning the transposition ie:

Code:
Dim TT as Variant
....
TT = Application.WorksheetFunction.Transpose(T)

Best regards

Richard
 

Watch MrExcel Video

Forum statistics

Threads
1,113,955
Messages
5,545,162
Members
410,667
Latest member
Gaexel
Top