Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 直到循环不工作为止。有什么想法吗?_Excel_Vba_Nested Loops - Fatal编程技术网

Excel 直到循环不工作为止。有什么想法吗?

Excel 直到循环不工作为止。有什么想法吗?,excel,vba,nested-loops,Excel,Vba,Nested Loops,我正在尝试制作一个程序来移动单元格的范围,但是我的一个Do循环不起作用。特别是列爬行的元素。当程序运行时,仅填写A7:A9而不是A7:J9。爬行在第1行到L1的移动中起作用,并且在红线中没有值时起作用(如果A10为空,则B7:B9将填充)。我犯了什么错 Sub Columntest() Dim i As Integer, j As Integer, k As Integer i = 1 j = 2 k = 7 Do Until i = 11 Ran

我正在尝试制作一个程序来移动单元格的范围,但是我的一个Do循环不起作用。特别是列爬行的元素。当程序运行时,仅填写A7:A9而不是A7:J9。爬行在第1行到L1的移动中起作用,并且在红线中没有值时起作用(如果A10为空,则B7:B9将填充)。我犯了什么错

Sub Columntest()
Dim i As Integer, j As Integer, k As Integer
    i = 1
    j = 2
    k = 7
    Do Until i = 11
        Range("L1").Formula = Cells(1, i)
        If Cells(10, i).Value = "Low" Then
            Do Until j = 6
                Cells(j + 15, 1).Formula = Cells(j, i)
            j = j + 1
            Loop
                Do Until k = 10
                    Cells(k + 5, 1).Copy
                    Cells(k, i).PasteSpecial xlPasteValues
                k = k + 1
                Loop
        End If
        If Cells(10, i).Value = "High" Then
            Do Until j = 6
                Cells(j + 15, 1).Formula = Cells(j, i)
            j = j + 1
            Loop
                Do Until k = 10
                    Cells(k + 5, 2).Copy
                    Cells(k, i).PasteSpecial xlPasteValues
                k = k + 1
                    Loop
        End If
    i = i + 1
    Loop

End Sub

J&K变量应在do while循环内设置为默认值:

i = 1

Do Until i = 11

    j = 2
    k = 7
    ......
    ......
    ...... and so son  

因为一旦J&K在第一次循环后达到最大值,在您重置J&K值之前,它将永远不会再次进入J&K的Do While循环。

您是否仔细检查过它,以查看它出错的地方?如果K或J循环中的任何一个被保留,则它不会移动到第二列等。问题似乎是Do循环在结束If函数后认为它已完成。谢谢。现在这个很好用,我会投赞成票,但我还没有这个名声。没关系。很高兴我能帮忙。谢谢,V