超まとめ
WorksheetFunction.Transpose(<二次元配列>)で、行と列を入れ替えた結果(2次元配列)を取得できます。
変換後の配列の開始インデックスは1からになることに注意が必要です。
詳しく
二次元配列を作って、WorksheetFunction.Transposeを使って行と列を入れ替えるサンプルプログラムです。
5
ReDim
baseArray(1
To
3, 1
To
2)
11
For
cnt1 = LBound(baseArray, 1)
To
UBound(baseArray, 1)
12
For
cnt2 = LBound(baseArray, 2)
To
UBound(baseArray, 2)
13
baseArray(cnt1, cnt2) = currentValue
14
currentValue = currentValue + 1
20
transedArray = WorksheetFunction.Transpose(baseArray)
実行結果
baseArrayが元々の二次元配列(2×3)で、transedArrayが行列入れ替えを行ったあとの配列です。
| 0 | 1 |
| 2 | 3 |
| 4 | 5 |
が
| 0 | 2 | 4 |
| 1 | 3 | 5 |
に変換され、行と列が入れ替わっているのがわかります。
注意点
Transposeの結果として得た二次元配列は、開始インデックスが「1」です。
入れ替え前の配列の開始インデックスがなんであろうと、1からスタートになりますので、この点は注意して遣う必要があります。
投稿ナビゲーション
Thank you for the auspicious writeup. It in fact was a amusement account
it. Look advanced to far added agreeable from you! However,
how could we communicate?
Please on Twitter. My Account is @tfumiaki .
I am genuinely pleased to glance at this blog posts which includes
tons of helpful data, thanks for providing these kinds of information.