无效的外部程序错误与VBA

我正试图将几个数据单元格与相同的标签结合起来。 将有2或3(也占1)重复单元格。 我一直得到一个无效的外部程序错误函数。 它突出了“模块模块1”,所以我认为这与定义我的课程有关,但是我不能用VBA来弄清楚。

Module Module1 Public Sub Main() Dim num As Integer num = 2 Dim val As Integer val = 2 While num <= 5031 If StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 And StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 Then Cells(val, 5) = Calls(num, 3).Value Cells(val, 6) = Add(Cells(num, 4).Value, Cells(num + 1, 4).Value, Cells(num + 2, 4).Value) num = num + 3 val = val + 1 End If ElseIf StrComp(Cells(num, 3).Value, Cells((num + 1), 3).Value, vbTextCompare) = 0 Then Cells(val, 5) = Calls(num, 3).Value Cells(val, 6) = Add(Cells(num, 4).Value, Cells(num + 1, 4).Value) num = num + 2 val = val + 1 End If Else Cells(val, 5) = Calls(num, 3).Value Cells(val, 6) = Cells(num, 4).Value num = num + 1 val = val + 1 End If Wend End Sub 

删除多余的End If语句。 VBA If ... Then ... Else格式如下:

 If choice Then Statements... ElseIf nextChoice Then Statements... ...as Many Elseif's as you need Else Statements... End If 

我相信VBA编译器无法从额外的End If语句中恢复