gpt4 book ai didi

vba - 编译错误 : End If without block If

转载 作者:行者123 更新时间:2023-12-05 01:28:15 24 4
gpt4 key购买 nike

我目前正在运行以下循环以从另一个电子表格中提取信息,但不断收到以下错误消息编译错误:结束如果没有 block 如果,在

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 ] ]

关于vba - 编译错误 : End If without block If,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22580516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com