我将如何逐行循环或重复宏?

时间:2016-11-02 15:17:51

标签: excel vba excel-vba

代码当前查找所有组合行数据。用逗号分隔它们并将它们分成5列。我试图在完成第一行后继续运行并查看下一行。谢谢

   Sub Tax()

Dim c1() As String
Dim c2() As String
Dim c3() As String
Dim c4() As String
Dim c5() As String
Dim out() As Variant

Dim j, k, l, m, n, o As Long

Dim col1 As Range
Dim col2 As Range
Dim col3 As Range
Dim col4 As Range
Dim col5 As Range
Dim out1 As Range

Set col1 = Range("A1")
Set col2 = Range("B1")
Set col3 = Range("C1")
Set col4 = Range("D1")
Set col5 = Range("E1")

c1 = Split(col1.Value, ",")
c2 = Split(col2.Value, ",")
c3 = Split(col3.Value, ",")
c4 = Split(col4.Value, ",")
c5 = Split(col5.Value, ",")

Set out1 = Range("A1", Range("E1").Offset((UBound(c1) + 1) * (UBound(c2) + 1) * (UBound(c3) + 1) * (UBound(c4) + 1) * (UBound(c5) + 1)))

out = out1

j = 0
k = 0
l = 0
m = 0
n = 0
o = 1

Do While j <= UBound(c1)
    Do While k <= UBound(c2)
        Do While l <= UBound(c3)
            Do While m <= UBound(c4)
                Do While n <= UBound(c5)
                    out(o, 1) = c1(j)
                    out(o, 2) = c2(k)
                    out(o, 3) = c3(l)
                    out(o, 4) = c4(m)
                    out(o, 5) = c5(n)
                    o = o + 1
                    n = n + 1
                Loop
                n = 0
                m = m + 1
            Loop
            m = 0
            l = l + 1
        Loop
        l = 0
        k = k + 1
    Loop
    k = 0
    j = j + 1
Loop
out1.Value = out
End Sub

0 个答案:

没有答案