Answers:
将数据复制到一个或多个列或行中。
在粘贴复制的数据之前,右键单击第一个目标单元格(要将数据粘贴到其中的行或列的第一个单元格),然后单击“选择性粘贴”。
在“选择性粘贴”对话框中,选择“转置”,然后单击“确定”。
您将在对话框的右下角找到“切换”复选框:
本文来自Excel 2003帮助,但该过程一直适用于最新的Excel。但是,对话框可能看起来不同。
以下VBA代码可以解决问题。
Sub FlattenToSingleCol()
Cells(1, 1).Activate ' Go to the top left
' Go past the last row that starts with a word
Do Until IsEmpty(ActiveCell)
DoEvents
ActiveCell.Offset(1).Select
Loop
' Set curRow to the last row that starts with a word (the row above ActiveCell)
curRow = ActiveCell.Row - 1
Do While curRow > 0
DoEvents
Cells(curRow, 1).Activate
' Go right past the last cell that contains a word
Do Until IsEmpty(ActiveCell)
DoEvents
ActiveCell.Offset(0, 1).Activate
Loop
' Come back left to the last cell that contains a word
If ActiveCell.Column > 1 Then
ActiveCell.Offset(0, -1).Activate
End If
' Insert a new row below the current one for each
Do Until ActiveCell.Column = 1 ' Move each non-empty cell to a new row and move left to the edge
DoEvents
ActiveCell.Offset(1).EntireRow.Insert
Cells(ActiveCell.Row + 1, 1).Value = ActiveCell.Value
ActiveCell.Clear
ActiveCell.Offset(0, -1).Select
Loop
' Go to the row above. Processing from the bottom up avoids re-processing lines we just inserted below.
curRow = ActiveCell.Row - 1
Loop
End Sub