我目前正在运行以下循环以从其他电子表格中提取信息,但不断收到以下错误消息编译错误:结束如果没有阻止,则
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
答案 0 :(得分:5)
根据我上面的评论,将代码更改为
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 ] ]