我不确定为什么会抛出编译错误并告诉我我有一个没有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的新手。我搜索了答案,但我发现的一切看起来都像这样。
答案 0 :(得分:0)
这是因为With
阻止:
With Ws.Range("cGroup") 'where to look
永远不会在放置它的If
块中结束。