我需要将每一行拆分为2当第6列中的值以逗号分隔时(多行)。
示例(从2行开始):
@extend
变成了:
A B C D E F G0 ,G1
A* B* C* D* E* F* G0*,G1*
答案 0 :(得分:1)
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