【发布时间】:2014-08-10 13:10:37
【问题描述】:
我不确定为什么这会引发编译错误并告诉我我有一个没有 If 的 Else。错误出现在 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 的新手。我搜索了答案,但我找到的一切看起来都是这样的。
【问题讨论】:
标签: excel if-statement compiler-errors excel-2007 vba