Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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编译错误-如果或Select或Sub或函数或语句结尾,则应为_Excel_Vba_Compiler Errors - Fatal编程技术网

Excel VBA编译错误-如果或Select或Sub或函数或语句结尾,则应为

Excel VBA编译错误-如果或Select或Sub或函数或语句结尾,则应为,excel,vba,compiler-errors,Excel,Vba,Compiler Errors,我最近遇到一个VBA编译错误: “应为:If或Select或Sub或Function或Property或Type或With或Enum或End of statement” 我所有的if语句都已关闭,我没有看到任何其他语法错误 代码如下: Option Explicit Sub whileloop() Dim intCurrentRow As Integer Dim intLastRow As Integer Dim strPrefix As String Dim strSuffix As St

我最近遇到一个VBA编译错误: “应为:If或Select或Sub或Function或Property或Type或With或Enum或End of statement”

我所有的if语句都已关闭,我没有看到任何其他语法错误

代码如下:

Option Explicit

Sub whileloop()

Dim intCurrentRow As Integer
Dim intLastRow As Integer
Dim strPrefix As String
Dim strSuffix As String
Dim strOperation As String
Dim snglLaborMinutes As Single



intCurrentRow = 3
intLastRow = Cells(Rows.Count, 0).End(xlUp).Row
strPrefix = Cells(2, 0).Value
strSuffix = Cells(2, 1).Value
strOperation = Cells(2, 4).Value
snglLaborMinutes = Cells(2, 3).Value

While intCurrentRow <= intLastRow
    If strPrefix = Cells(intCurrentRow, 0).Value Then
        If strSuffix = Cells(intCurrentRow, 1).Value Then
            If strOperation = Cells(intCurrentRow, 4).Value Then
                snglLaborMinutes = snglLaborMinutes + Cells(intCurrentRow, 3).Value
                Cells(intCurrentRow - 1, 3).Value = snglLaborMinutes
                Rows(1).EntireRow.Delete
                intLastRow = intLastRow - 1
                intCurrentRow = intCurrentRow - 1
            Else
                strOperation = Cells(intCurrentRow, 4).Value
            End If
        Else
             strSuffix = Cells(intCurrentRow, 1).Value
        End If
    Else
         strPrefix = Cells(intCurrentRow, 0).Value
    End If

intCurrentRow = intCurrentRow + 1

End While


End Sub
选项显式
子whileloop()
将intCurrentRow设置为整数
将intLastRow设置为整数
作为字符串的Dim strPrefix
作为字符串的Dim strSuffix
作为字符串的Dim STRO操作
昏暗的灯光使人感觉像是单身
intCurrentRow=3
intLastRow=单元格(Rows.Count,0).End(xlUp).Row
strPrefix=单元格(2,0).值
strSuffix=单元格(2,1).值
strOperation=单元格(2,4).值
snglLaborMinutes=单元格(2,3).值

While intCurrentRow可以查找While的语法,但为了向后兼容,保留了它

你最好用


这是
Wend
,不是吗?或者
Do While
loop
不确定两者之间是否有任何区别。@Warcupine-
Do While
更好,因为你可以
退出Do
。这里也解释了区别。这是一个关于谢谢你的非常好的教程,是的,结束语是“Wend”,但我把它改为Do While/Exit Do
While intCurrentRow <= intLastRow
  ' .... 

   intCurrentRow = intCurrentRow + 1

Wend
Do While intCurrentRow <= intLastRow
   ' ....

    intCurrentRow = intCurrentRow + 1

Loop
Dim i as long
For i = intCurrentRow To intLastRow


    ' intCurrentRow = intCurrentRow + 1  not needed any longer

Next i