vba 编译错误:End If without block If
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22580516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compile error: End If without block If
提问by methuselah
I am currently running the below loop to pull out information from another spreadsheet, but keep getting the following error message Compile error: End If without block If, at
我目前正在运行以下循环以从另一个电子表格中提取信息,但不断收到以下错误消息Compile error: End If without block If, at
ElseIf cel.Offset(0, 8).Value = "" Then wshT.Cells(r, 14).Value = "Physical"
What could be causing it and how do I remediate it? My code below:
可能是什么原因造成的,我该如何补救?我的代码如下:
' 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
回答by Siddharth Rout
Further to my comments above, change your code to
根据我上面的评论,将您的代码更改为
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
or to this
或为此
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
For the syntax of IF/EndIf
, see the below
有关 的语法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 ] ]