编译错误:结束如果没有块if [英] Compile error: End If without block If

查看:618
本文介绍了编译错误:结束如果没有块if的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行以下循环,从另一个电子表格中提取信息,但仍然收到以下错误信息编译错误:结束如果不阻止,请在

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

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

 '在main.xlsm上循环列A中的单元格
对于r = 1到m

'我们可以在列A中找到值
Set cel = wshS.Columns(3).Find(what:= wshT.Cells(r,1).Value,_
LookAt:= xlWhole,MatchCase:= False)

如果不是cel Is Nothing然后
如果cel.Offset(0,8).Value =是然后wshT.Cells(r ,14).Value =Virtual
ElseIf cel.Offset(0,8).Value =Then wshT.Cells(r,14).Value =Physical
Else:End If
结束如果
下一步r


解决方案

进一步的我上面的评论,将你的代码更改为

 如果不是cel Is Nothing然后
如果cel.Offset 0,8).Value =Yes然后wshT.Cells(r,14).Value =Virtual
如果cel.Offset(0,8).Value =然后wshT.Cells(r, 14).Value =Physical
End If

或此

 如果不是cel是没有的n 
如果cel.Offset(0,8).Value =Yes然后
wshT.Cells(r,14).Value =Virtual
ElseIf cel.Offset(0, 8).Value =然后
wshT.Cells(r,14).Value =Physical
End If
End If
/ pre>

有关 IF / EndIf 的语法,请参阅以下

 '~~>多行语法:
如果条件[Then]
[statements]
[ElseIf elseifcondition [Then]
[elseifstatements]]
[Else
[ elsestatements]]
结束如果

'~~>单行语法:
如果条件Then [statements] [Else [elsestatements]]


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

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

解决方案

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

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

'~~> Single-line syntax:
If Condition Then [ statements ] [ Else [ elsestatements ] ]

这篇关于编译错误:结束如果没有块if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆