Visual Basic使用Macro将单元格中的各行划分为excel中的不同行

时间:2016-03-22 05:57:58

标签: excel vba excel-vba

如何使用宏使用可视基本代码将单元格中的各个行划分为excel中的不同行并在另一个工作表中打印行

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码将单个单元格中的多行数据拆分为另一张表格中的不同行:

Sub splitCell()
    r = 1    'cell data will copied starting from this row number in sheet 2
    temp = Split(Sheet1.Range("A1"), Chr(10))
    For i = LBound(temp) To UBound(temp)
        Sheet2.Cells(r, 1).Value = temp(i)    'data will be pasted in the 1st column of sheet 2
        r = r + 1
    Next
End Sub