Sub 拆分()
Dim ar As Variant
Dim br()
ar = Sheets("原始").[a1].CurrentRegion
ReDim br(1 To UBound(ar) * 50, 1 To UBound(ar, 2))
For i = 1 To UBound(ar)
If InStr(ar(i, 4), Chr(10)) = 0 Then
n = n + 1
For j = 1 To UBound(ar, 2)
br(n, j) = ar(i, j)
Next j
ElseIf InStr(ar(i, 4), Chr(10)) > 0 Then
rr = Split(ar(i, 4), Chr(10))
For s = 0 To UBound(rr)
n = n + 1
For j = 1 To UBound(ar, 2)
If j <> 4 Then
br(n, j) = ar(i, j)
End If
Next j
br(n, 4) = rr(s)
Next s
End If
Next i
With Sheets("结果")
.[a1].CurrentRegion = Empty
.[a1].Resize(n, UBound(br, 2)) = br
End With
MsgBox "ok!"
End Sub
|