Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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 VBA中的不同表格_Excel_Vba - Fatal编程技术网

中断循环并将结果输入Excel VBA中的不同表格

中断循环并将结果输入Excel VBA中的不同表格,excel,vba,Excel,Vba,从API获取结果并将其排序到不同的文件中,问题是我从API返回了20列,我想要两个不同的表,每个表有10个结果 j = 3 For Each result In JSON.Item("results") Cells(20, j) = result.Item("param_1") Cells(21, j) = result.Item("param_2") Cells(22, j) = result.Item("param_3") Cells(23, j) = result.Item("param

从API获取结果并将其排序到不同的文件中,问题是我从API返回了20列,我想要两个不同的表,每个表有10个结果

j = 3
For Each result In JSON.Item("results")

Cells(20, j) = result.Item("param_1")
Cells(21, j) = result.Item("param_2")
Cells(22, j) = result.Item("param_3")
Cells(23, j) = result.Item("param_4")
i = 0

For Each t In result.Item("param_5")
    If i > 0 Then
        Cells(24, j) = Cells(24, j) & ", " & t
    Else
        Cells(24, j) = t
        i = i + 1
    End If
Next
Cells(25, j) = result.Item("param_6")
Cells(26, j) = result.Item("param_7")
j = j + 1
Next
这对于每20列都很有效,问题是当我在第一部分下添加这部分代码时,显然它在第一个表中效果不好,我得到了10个结果,但在下一个表中我只有一个条目

If j >= 13 Then
j = 3

Cells(33, j) = result.Item("param_1")
Cells(34, j) = result.Item("param_2")
Cells(35, j) = result.Item("param_3")
Cells(36, j) = result.Item("param_4")
i = 0
For Each t In result.Item("param_5")
    If i > 0 Then
        Cells(37, j) = Cells(37, j) & ", " & t
    Else
        Cells(37, j) = t
        i = i + 1
    End If
Next
Cells(38, j) = result.Item("param_6")
Cells(39, j) = result.Item("param_7")

我建议你展示一些前后的实际数据。它不一定是你自己的数据——只是一些简单的演示。专注于展示你想要什么以及哪里出了问题。如果你这样做,我相信你会得到帮助。我在这里猜测一点,因为我觉得问题不清楚,但我猜测你希望“j”递增,但你在第二个“for/next”循环中没有像在第一块代码中那样的“j”。除此之外,虽然…这应该是直接调试,所以我将描述一些基本的调试。。。在您看到不起作用的地方附近插入一个中断(即单击编辑窗口的左侧)。点击f5开始,让宏到达断点,然后点击“f8”一步一步地移动,以观察输出并确定哪里出了问题。您的问题不清楚,因为您正在请求每列2列then值,之后您将公开您的代码在20列中工作正常。你能上传一些输入和预期输出的截图吗?谢谢@dra_red,我已经调试好了。若j>=13,那个么在下面加上n=3,另一个for循环进入第二个表。很高兴听到你们对它进行了排序,米伦科。干杯