excel - 否则,如果没有编译错误

标签 excel if-statement compiler-errors excel-2007 vba

我不确定为什么这会引发编译错误并告诉我我有一个其他的If。错误出现在ElseIf行上。其他一切似乎都在起作用。有什么建议?

If IsEmpty(Me.ComboBox15.Value) = False Then
    strFind = Me.ComboBox15.Value    'what to look for
    With Ws.Range("cGroup")  'where to look
    Sheet2.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=ComboBox15.Value
    Set c = .Find(strFind, LookIn:=xlValues)
        'c.Select
        If Not c Is Nothing Then
            With Me
                .ComboBox15.Value = c.Offset(0, 0).Value
                .ComboBox16.Value = c.Offset(0, 1).Value
                .ComboBox17.Value = c.Offset(0, 2).Value
                .ComboBox1.Value = c.Offset(0, 3).Value
                .ComboBox19.Value = c.Offset(0, 4).Value
                r = c.Row
                f = 0
            End With
            FirstAddress = c.Address
        Else: MsgBox strFind & "Not listed"    'search failed
        End If
ElseIf IsEmpty(Me.ComboBox16.Value) = False Then
    strFind = Me.ComboBox16.Value    'what to look for
        With Ws.Range("cGeography")  'where to look
        Sheet2.ListObjects("Table1").Range.AutoFilter Field:=2,  Criteria1:=ComboBox16.Value
        Set c = .Find(strFind, LookIn:=xlValues)
            'c.Select
            If Not c Is Nothing Then
                With Me
                    .ComboBox15.Value = c.Offset(0, -1).Value
                    .ComboBox16.Value = c.Offset(0, 0).Value
                    .ComboBox17.Value = c.Offset(0, 1).Value
                    .ComboBox1.Value = c.Offset(0, 2).Value
                    r = c.Row
                    f = 0
                End With
                FirstAddress = c.Address
            Else: MsgBox strFind & "Not listed"    'search failed
            End If
        End With
ElseIf Not IsEmpty(Me.ComboBox17.Value) Then
            strFind = Me.ComboBox17.Value    'what to look for
            With Ws.Range("cDept")  'where to look
            Sheet2.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:=ComboBox17.Value
            Set c = .Find(strFind, LookIn:=xlValues)
                'c.Select
                If Not c Is Nothing Then
                    With Me
                        .ComboBox15.Value = c.Offset(0, -2).Value
                        .ComboBox16.Value = c.Offset(0, -1).Value
                        .ComboBox17.Value = c.Offset(0, 0).Value
                        .ComboBox1.Value = c.Offset(0, 1).Value
                        r = c.Row
                        f = 0
                    End With
                    FirstAddress = c.Address
                Else: MsgBox strFind & "Not listed"    'search failed
                End If
            End With


Else: MsgBox "Error"
End If

对于任何格式/缩进错误,我深表歉意。我是VBA的新手。我搜索了答案,但是发现的一切看起来都是这样。

最佳答案

这是因为With块:

With Ws.Range("cGroup")  'where to look

永远不会在放置它的If块内结束。

关于excel - 否则,如果没有编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24316045/

相关文章:

if-statement - Swift 中的 If 语句兼容性问题(之前有效)

c - 函数my_find_node返回第一个节点出现的地址

excel - 如何在 Excel 中比较两个具有优先级的文本值?

java - 如何根据Java中的命令行参数使 "if"条件自动改变?

c - 为什么当我在 "else"语句后添加 "if"时,代码无法正常运行?

编译 c 源代码时找不到 -lagent(不兼容的库)

.net - 如何解决 JScript.NET 程序集引用错误 JS1259?

c# - 插入 Excel 工作表后调整图像大小

excel - 按关键字求和

excel - 从 InStr 函数返回 True/False bool 值?维巴