将单元格中的文本拆分为行,用于多列

Split text in cells at line breaks into rows, for multiple columns

我的问题是对此的扩展,Split text in cells at line breaks,其中,我需要将带有换行符的单元格中的文本拆分为单独的行,不仅针对一列,而且针对多列。

一个screenshot of my data:

只是建立在你的链接答案中所做的事情之上:

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