Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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
Vba 编译错误,下一步不带for_Vba_Excel - Fatal编程技术网

Vba 编译错误,下一步不带for

Vba 编译错误,下一步不带for,vba,excel,Vba,Excel,我不熟悉用excel vba编写代码,我收到了下面的编译错误,没有For…。但是我有For和Next,请告诉我我做错了什么,请查看下面的代码,谢谢 Dim i As Integer For i = 19 To 49 If Cells(3, i) > 499999 Then Cells(4, 3) = 499999 ElseIf Cells(3, i) < 499999 Then Cells(4, 3) = Cells(3, i)

我不熟悉用excel vba编写代码,我收到了下面的编译错误,没有For…。但是我有For和Next,请告诉我我做错了什么,请查看下面的代码,谢谢

Dim i As Integer

For i = 19 To 49

    If Cells(3, i) > 499999 Then
        Cells(4, 3) = 499999
    ElseIf Cells(3, i) < 499999 Then
        Cells(4, 3) = Cells(3, i)
    End If

    If Cells(4, 3) < 499999 Then
         Cells(4, 5) = 0
    If Cells(3, i) > 999999 Then
        Cells(4, 4) = 500000
    ElseIf Cells(3, i) < 999999 Then
        Cells(4, 4) = Cells(3, i) - 499999
    End If

    If Cells(4, 4) = 0 Then
         Cells(4, 5) = 0
    ElseIf Cells(3, i) > 1999999 Then
        Cells(4, 5) = 1000000
    ElseIf Cells(3, i) < 1999999 Then
        Cells(4, 5) = Cells(3, i) - 999999
    End If

    If Cells(4, 5) = 0 Then
         Cells(4, 6) = 0
    ElseIf Cells(3, i) > 4999999 Then
         Cells(4, 6) = 3000000
    ElseIf Cells(3, i) < 4999999 Then
        Cells(4, 6) = Cells(3, i) - 1999999
    End If

    If Cells(4, 6) = 3000000 Then
         Cells(4, 7) = Cells(3, i) - 4999999
    ElseIf Cells(4, 6) < 3000000 Then
         Cells(4, 7) = 0
    End If

    Range(7, i).Value = (Cells(5, 3) + Cells(5, 4) + Cells(5, 5) + Cells(5, 6) + Cells(5, 7)) / Cells(3, i)

 Next i

End Sub
Dim i作为整数
对于i=19到49
如果单元格(3,i)>499999,则
单元格(4,3)=499999
ElseIf细胞(3,i)<499999
单元(4,3)=单元(3,i)
如果结束
如果单元格(4,3)<499999,则
单元(4,5)=0
如果单元格(3,i)>999999,则
单元(4,4)=500000
ElseIf细胞(3,i)<999999
单元(4,4)=单元(3,i)-499999
如果结束
如果单元格(4,4)=0,则
单元(4,5)=0
ElseIf细胞(3,i)>1999999然后
单元(4,5)=1000000
ElseIf细胞(3,i)<1999999
单元(4,5)=单元(3,i)-99999
如果结束
如果单元格(4,5)=0,则
单元格(4,6)=0
ElseIf细胞(3,i)>499999
单元(4,6)=3000000
ElseIf细胞(3,i)<499999
单元(4,6)=单元(3,i)-1999999
如果结束
如果单元格(4,6)=3000000,则
单元(4,7)=单元(3,i)-499999
ElseIf细胞(4,6)<3000000
单元格(4,7)=0
如果结束
范围(7,i)。值=(单元格(5,3)+单元格(5,4)+单元格(5,5)+单元格(5,6)+单元格(5,7))/单元格(3,i)
接下来我
端接头

在第二个
块中,如果出现
块,请更换

If Cells(4, 3) < 499999 Then
     Cells(4, 5) = 0
If Cells(3, i) > 999999 Then
如果单元格(4,3)<499999,则
单元(4,5)=0
如果单元格(3,i)>999999,则

如果单元格(4,3)<499999,则
单元(4,5)=0
ElseIf细胞(3,i)>99999然后
这就是让VBA解释器感到困惑的地方。

如果单元格(4,3)<499999那么
 If Cells(4, 3) < 499999 Then
      Cells(4, 5) = 0
 If Cells(3, i) > 999999 Then *****needs to elseif
     Cells(4, 4) = 500000
 ElseIf Cells(3, i) < 999999 Then
     Cells(4, 4) = Cells(3, i) - 499999
 End If
单元(4,5)=0 如果单元格(3,i)>999999,则******需要elseif 单元(4,4)=500000 ElseIf细胞(3,i)<999999 单元(4,4)=单元(3,i)-499999 如果结束

你在最后一个If-blcok中得到了与代码不匹配的类型:
If-Cells(3,i)>99999然后
应该是
ElseIf-Cells(3,i)>99999然后
提示:下一次,注释掉所有If语句,然后一次取消注释一个If块,直到你找到错误为止
 If Cells(4, 3) < 499999 Then
      Cells(4, 5) = 0
 If Cells(3, i) > 999999 Then *****needs to elseif
     Cells(4, 4) = 500000
 ElseIf Cells(3, i) < 999999 Then
     Cells(4, 4) = Cells(3, i) - 499999
 End If