编译错误:End If without block If

我目前正在运行下面的循环来从另一个电子表格中提取信息,但不断收到以下错误消息编译错误:End If without block If ,at

ElseIf cel.Offset(0, 8).Value = "" Then wshT.Cells(r, 14).Value = "Physical" 

有什么可能导致它,我该如何补救? 我的代码如下:

 ' Loop though cells in column A on main.xlsm For r = 1 To m ' Can we find the value in column A Set cel = wshS.Columns(3).Find(What:=wshT.Cells(r, 1).Value, _ LookAt:=xlWhole, MatchCase:=False) If Not cel Is Nothing Then If cel.Offset(0, 8).Value = "Yes" Then wshT.Cells(r, 14).Value = "Virtual" ElseIf cel.Offset(0, 8).Value = "" Then wshT.Cells(r, 14).Value = "Physical" Else: End If End If Next r 

进一步对我上面的评论,改变你的代码

 If Not cel Is Nothing Then If cel.Offset(0, 8).Value = "Yes" Then wshT.Cells(r, 14).Value = "Virtual" If cel.Offset(0, 8).Value = "" Then wshT.Cells(r, 14).Value = "Physical" End If 

或对此

 If Not cel Is Nothing Then If cel.Offset(0, 8).Value = "Yes" Then wshT.Cells(r, 14).Value = "Virtual" ElseIf cel.Offset(0, 8).Value = "" Then wshT.Cells(r, 14).Value = "Physical" End If End If 

有关IF/EndIf的语法,请参阅下面的内容

 '~~> Multiple-line syntax: If condition [ Then ] [ statements ] [ ElseIf elseifcondition [ Then ] [ elseifstatements ] ] [ Else [ elsestatements ] ] End If '~~> Single-line syntax: If Condition Then [ statements ] [ Else [ elsestatements ] ]