如何分离与分隔值到各行的行?

问题描述 投票:0回答:1

在Excel中,我有需要拆分成新行分隔的数据多列。某些列有将需要被复制到新行单值。我只能看到分隔的数据一列在网络上的例子,所以不知道如何解决方法适用于包含分隔的数据多列。

我需要建立在多个列包含分隔列出每个项目分隔各行

我有的:

enter image description here

我需要的:

enter image description here

excel vba
1个回答
0
投票

这里是你如何能接近一个简单的例子:

Sub Test()

Dim MyArray1() As String, MyArray2() As String
Dim X As Long, Y As Long, Z As Long

Z = 7
For X = 2 To 4
    MyArray1() = Split(Replace(Cells(X, 2).Value, " ", ""), ",")
    MyArray2() = Split(Replace(Cells(X, 3).Value, " ", ""), ",")
    For Y = LBound(MyArray1) To UBound(MyArray1)
        Cells(Z, 1).Value = Cells(X, 1).Value
        Cells(Z, 2).Value = MyArray1(Y)
        Cells(Z, 3).Value = MyArray2(Y)
        Cells(Z, 4).Value = Cells(X, 4).Value
        Z = Z + 1
    Next Y
Next X

End Sub

下面的输出

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.