答案1
答案2
答案3
如果您愿意使用 VBA,这里有一个可以执行此操作的宏:
Sub splitByNewLine()
Dim pasteCell As Range, rowCumulationTotal As Integer
rowCumulationTotal = 0
On Error GoTo inputErrorHandling
Set pasteCell = Range(InputBox("Please enter target cell address"))
On Error GoTo 0
For i = 1 To Selection.Rows.Count
Dim rowCumulationCurrent As Integer, maxElemsOnRow As Integer
rowCumulationCurrent = 0
maxElemsOnRow = 0
For j = 1 To Selection.Columns.Count
Dim elems() As String, elemCount As Integer
elems = Split(Cells(Selection.Row + i - 1, Selection.Column + j - 1), vbLf)
elemCount = UBound(elems)
For k = 0 To elemCount
Cells(pasteCell.Row + i + rowCumulationTotal + k - 1, pasteCell.Column + j - 1) = elems(k)
If maxElemsOnRow < k Then
rowCumulationCurrent = rowCumulationCurrent + 1
maxElemsOnRow = k
End If
Next k
Next j
rowCumulationTotal = rowCumulationTotal + rowCumulationCurrent
Next i
Exit Sub
inputErrorHandling:
On Error GoTo 0
MsgBox ("You didn't enter valid cell address")
End Sub
要使用它,只需选择区域您想要转换并运行宏。它会要求您提供一个目标单元格,即要复制所选内容(或者更确切地说,复制将从此处开始)并进行所需拆分的单元格。