0
ROW1| 1 2 3
ROW2| A D G
ROW3| B E H
ROW4| C F I
我想這樣的輸出:Excel VBA中的多個列到一個單元格
ROW1| 1
ROW2| A
ROW3| B
ROW4| C
ROW1| 2
ROW2| D
ROW3| E
ROW4| F
ROW1| 3
ROW2| G
ROW3| H
ROW4| I
請幫我
ROW1| 1 2 3
ROW2| A D G
ROW3| B E H
ROW4| C F I
我想這樣的輸出:Excel VBA中的多個列到一個單元格
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解決方案:
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
你能後,你已經嘗試了一些代碼,並說明你正在嘗試才達到更好的或者可能上傳你的開始情況的圖片是什麼和結果爲例? –
Duplicate:https://stackoverflow.com/questions/38232626/using-vlookup-macros-to-transpose/38232974#38232974 –