我的问题是对此Split text in cells at line breaks的扩展,其中,我需要将包含换行符的单元格中的文本拆分为单独的行,不仅适用于一列,而且适用于多列。
答案 0 :(得分:2)
只是建立在你的链接答案中所做的事情:
Sub JustDoIt2()
'working for active sheet
'copy to the end of sheets collection
ActiveSheet.Copy after:=Sheets(Sheets.Count)
Dim tmpArr As Variant
Dim Cell As Range
For Each Cell In Range("A2", Range("A2").End(xltoright).End(xlDown))
If InStr(1, Cell, Chr(10)) <> 0 Then
tmpArr = Split(Cell, Chr(10))
If Cell.Offset(1) <> Cell Then
Cell.EntireRow.Copy
Cell.Offset(1, 0).Resize(UBound(tmpArr), 1). _
EntireRow.Insert xlShiftDown
End If
Cell.Resize(UBound(tmpArr) + 1, 1) = Application.Transpose(tmpArr)
End If
Next
Application.CutCopyMode = False
End Sub