VBA无效的外部过程错误

时间:2017-12-07 19:26:27

标签: excel vba

我正在尝试将几个数据单元与相同的标签组合在一起。将有2或3个(也占1个)重复细胞。我一直收到无效的外部程序错误功能。它突出了“模块module1”所以我认为它与定义我的类有关,但我不熟悉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

1 个答案:

答案 0 :(得分:0)

删除额外的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语句中恢复