2017-07-28 60 views
-3

单元格中的2行日期(可以是任何内容)。需要检测由\ n(新行?)分隔的单元格中的条目,并且具有为每个行条目分割单元格的功能。单元格有3个插入的数据行。如何将其分割成每行数据的行

所以我想象的地方它会检测新行的文字(\ n或其他),而且它将开始创造新的细胞抓住它\ n

enter image description here

+1

请更具体 –

+1

请发表您已经尝试 – Rominus

+0

感谢,但我没有写任何代码的代码。我在问如何将它放入代码中是可行的。 (我没有要求任何人为我写代码)。这是一个业务需求,我不知道它是否可以直接安装到Excel中。 –

回答

0

之前检测假设数据你的数据在Column A,你想输出在Column C分割数据,下面可能会有所帮助:

Option Explicit 

Sub splitCell() 
    Dim lastRow As Long, rowInd As Long, i As Long 
    Dim tempArr As Variant 
    Dim ws As Worksheet 

    Set ws = ThisWorkbook.Sheets("Sheet1") 'Change Sheet1 to your worksheet 

    With ws 
     rowInd = 1 
     lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'get last row with data in Column A 
     For i = 1 To lastRow 'looping tgrough all the cells in Column A 
      tempArr = Split(.Range("A" & i), Chr(10)) 'Chr(10) is line break code 
      .Range("C" & rowInd).Resize(UBound(tempArr) + 1, 1) = Application.Transpose(tempArr) 
      rowInd = rowInd + UBound(tempArr) + 1 
     Next i 
    End With 
End Sub 

查看图像以供参考。

enter image description here

0

作为工作表公式,

=TRIM(MID(SUBSTITUTE(P$1, CHAR(10), REPT(CHAR(32), LEN(P$1))), (ROW(1:1)-1)*LEN(P$1)+1, LEN(P$1))) 

enter image description here

相关问题