如何移調範圍(水平到垂直反之亦然)
Sub TransposeRangeValues()
Dim TmpArray() As Variant, FromRange as Range, ToRange as Range
set FromRange = Sheets("Sheet1").Range("a1:a12") 'Worksheets(1).Range("a1:p1")
set ToRange = ThisWorkbook.Sheets("Sheet1").Range("a1") 'ThisWorkbook.Sheets("Sheet1").Range("a1")
TmpArray = Application.Transpose(FromRange.Value)
FromRange.Clear
ToRange.Resize(FromRange.Columns.Count,FromRange.Rows.Count).Value2 = TmpArray
End Sub
注意:Copy / PasteSpecial 還有一個 Paste Transpose 選項,用於更新轉置單元格的公式。