单元格的值由逗号分隔时复制行

时间:2016-07-30 17:40:37

标签: arrays excel vba excel-vba flatten

我需要将每一行拆分为2当第6列中的值以逗号分隔时(多行)。

示例(从2行开始):

@extend

变成了:

A  B  C  D  E  F  G0 ,G1 
A* B* C* D* E* F* G0*,G1*

1 个答案:

答案 0 :(得分:1)

  

重新定位Split delimited 2nd and 3rd column data into new rows

Option Explicit

Sub split_out()
    Dim v As Long, vVALs As Variant, vSPLITs As Variant
    Dim rw As Long, lr As Long, mx As Long

    With Worksheets("Sheet4")
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        For rw = lr To 2 Step -1
            vVALs = .Cells(rw, 1).Resize(1, 7).Value2
            vSPLITs = Split(vVALs(1, 7), Chr(44))
            For v = UBound(vSPLITs) To LBound(vSPLITs) + 1 Step -1
                .Rows(rw + 1).EntireRow.Insert
                .Cells(rw + 1, 1).Resize(1, 6) = _
                    Array(vVALs(1, 1), vVALs(1, 2), vVALs(1, 3), vVALs(1, 4), vVALs(1, 5), vVALs(1, 6))
                .Cells(rw + 1, 7) = Trim(vSPLITs(v))
            Next v
            .Cells(rw, 7) = Trim(vSPLITs(v))
        Next rw
    End With

End Sub

enter image description here
从此......

enter image description here
...进入这个。