Excel 编译错误:如果没有块IF,则结束(持续错误)

Excel 编译错误:如果没有块IF,则结束(持续错误),excel,compiler-errors,vba,Excel,Compiler Errors,Vba,我真的需要帮助这个项目,我正在工作,但我似乎无法摆脱这个错误我的背部。有谁能推荐解决方案吗 Sub Dsurvey() Dim i As Integer Dim j As Integer Dim k As Integer k = 3 For i = 3 To 22 j = j + 1 If Sheets("2").Cells(j, "A").Value - Sheets("2").Cells(i, "A").Value

我真的需要帮助这个项目,我正在工作,但我似乎无法摆脱这个错误我的背部。有谁能推荐解决方案吗

Sub Dsurvey()
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer

    k = 3

    For i = 3 To 22
        j = j + 1
        If Sheets("2").Cells(j, "A").Value - Sheets("2").Cells(i, "A").Value = Sheets("2").Cells(j, "B").Value - Sheets("2").Cells(i, "B").Value Then
            Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(i, "A").Value
            Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(i, "B").Value
            Do While Sheets("2").Cells(k, "J").Value <= Sheets("2").Cells(j, "A").Value
                    Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(k - 1, "J").Value + 100
                    Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(k - 1, "K").Value + 100
                    k = k + 1

        End If
    Next i

End Sub
Sub-Dsurvey()
作为整数的Dim i
作为整数的Dim j
将k变为整数
k=3
对于i=3到22
j=j+1
如果表(“2”).单元格(j,“A”).数值-表(“2”).单元格(i,“A”).数值=表(“2”).单元格(j,“B”).数值-表(“2”).单元格(i,“B”).数值,则
表(“2”).单元格(k,“J”).值=表(“2”).单元格(i,“A”).值
表(“2”).单元格(k,“k”).值=表(“2”).单元格(i,“B”).值

Do While Sheets(“2”).单元格(k,“J”).值如果
,则不会缺少
结束,但不会使用
循环关闭
Do While

k = 3
For i = 3 To 22
    j = j + 1
    If Sheets("2").Cells(j, "A").Value - Sheets("2").Cells(i, "A").Value = Sheets("2").Cells(j, "B").Value - Sheets("2").Cells(i, "B").Value Then
        Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(i, "A").Value
        Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(i, "B").Value
        Do While Sheets("2").Cells(k, "J").Value <= Sheets("2").Cells(j, "A").Value
            Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(k - 1, "J").Value + 100
            Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(k - 1, "K").Value + 100
            k = k + 1
        Loop
    End If
Next i
k=3
对于i=3到22
j=j+1
如果表(“2”).单元格(j,“A”).数值-表(“2”).单元格(i,“A”).数值=表(“2”).单元格(j,“B”).数值-表(“2”).单元格(i,“B”).数值,则
表(“2”).单元格(k,“J”).值=表(“2”).单元格(i,“A”).值
表(“2”).单元格(k,“k”).值=表(“2”).单元格(i,“B”).值

多谢你的帮助。现在它在if语句中显示类型不匹配。知道这个错误的来源吗?看起来至少有一个不是数值;因此,
类型不匹配
无法在数学运算中使用非数值。谢谢,我将交叉检查正在操作的单元格。请参阅上面的我的版本,该版本检查数值并输出到VBE的即时窗口(VBE,Ctrl+G)。
k = 3
With Sheets("2")
    For i = 3 To 22
        j = j + 1
        If IsNumeric(.Cells(j, "A")) And IsNumeric(.Cells(i, "A")) And IsNumeric(.Cells(j, "B")) And IsNumeric(.Cells(i, "B")) Then
            If .Cells(j, "A").Value - .Cells(i, "A").Value = .Cells(j, "B").Value - .Cells(i, "B").Value Then
                .Cells(k, "J").Value = .Cells(i, "A").Value
                .Cells(k, "K").Value = .Cells(i, "B").Value
                Do While .Cells(k, "J").Value <= .Cells(j, "A").Value
                    .Cells(k, "J").Value = .Cells(k - 1, "J").Value + 100
                    .Cells(k, "K").Value = .Cells(k - 1, "K").Value + 100
                    k = k + 1
                Loop
            End If
        Else
            Debug.Print "Not numeric: & " & i & Chr(45) & j & Chr(45) & k
        End If
    Next i
End With