Excel vba多列到一个单元格

ROW1| 1 2 3 ROW2| ADG ROW3| BEH ROW4| CFI 

我想要这样的输出:

 ROW1| 1 ROW2| A ROW3| B ROW4| C ROW1| 2 ROW2| D ROW3| E ROW4| F ROW1| 3 ROW2| G ROW3| H ROW4| I 

请帮帮我

试试这个公式:

 =IFERROR(INDEX($A$1:$C$4,MOD(ROW()-1,4)+1,INT((ROW()-1)/4)+1),"") 

并根据需要拖放/复制。

在这里输入图像说明

VBA解决scheme:

 Sub RowsToColumn() Dim dict As Object Dim lastRow As Long, lastColumn As Long, cnt As Long Dim myRng As Range Set dict = CreateObject("Scripting.Dictionary") 'get last row and column with data lastRow = Cells(Rows.Count, "A").End(xlUp).Row lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column 'set your range here 'Set myRng = Range("A1:C4") Set myRng = Range(Cells(1, 1), Cells(lastRow, lastColumn)) cnt = 1 'put cell value in dictionary For Each col In myRng.Columns For Each cel In col.Cells dict.Add cel.Value, cnt cnt = cnt + 1 Next cel Next col 'display values in dictionary Range("E1").Resize(dict.Count) = Application.Transpose(dict.keys) End Sub