“编译错误:否则没有如果”

我有错误的VBAmacros没有任何意义(我曾经有过问题,看清楚IF语句)。 错误信息:

编译错误:否则无If

代码(中间值定理的开发示范):

Option Explicit Sub Function1() Dim Polynomial As String Dim Sign Dim counter As Integer Dim Degree Dim Coefficient While Cells(counter + 1, 1).Value <> "" And Cells(counter + 1, 2).Value <> "" '+1 because top row occupied by column A, column B titles. If cell is empty stop. MsgBox "Enter polynomial by terms." Degree = Cells(counter + 1, 1).Value 'A2 Coefficient = Cells(counter + 1, 2).Value 'B2 If (Coefficient < 0) Then Sign = " - " ' if coefficient negative Else: If Coefficient > 0 Then Sign = " + " ' if coefficient positive End If Polynomial = Polynomial & " " & Coefficient & "x^" & Degree 'concatenation string, list polynomial. counter = 1 counter = counter + 1 Wend ' Finally: MsgBox poly End Sub 

更改为:

 If (Coefficient < 0) Then Sign = " - " ' if coefficient negative Else If Coefficient > 0 Then Sign = " + " ' if coefficient positive End If 

然后你需要有一个新的线。 否则if语句在行尾自动closures。 而且VBA抱怨说,看到Else的时候没有开放的阻挡。