IF-ELSE声明错误

时间:2018-06-25 09:45:06

标签: excel vba

我正在使用以下代码,如果参数arrRecords中有数据,则打印数据,如果参数arrRecordsarrRecords = ""中无数据,则打印跳过此步骤并离开。


If IsEmpty(arrRecords) = True Then
GoTo Get_Out

ElseIf IsEmpty(arrRecords) = Fales Then
PrintArray arrRecords, Y, Lastrecord, 1

End If

Get_Out:

我还在每次循环后使用arrRecords清除arrRecords = ""中的数据。仍然在有数据或无数据的情况下,代码始终转到Print语句。任何人都可以在这里帮助我。

1 个答案:

答案 0 :(得分:0)

从一般角度看

  1. 如果您在同一行的Then之后有其他内容,请终止If。如果您有以下ElseIf,则会收到语法错误。
  2. 使用Option Explicit拾取诸如Fales之类的错字。
  3. 您不需要= True,只需If IsEmpty(arrRecords)
  4. 如果没有Else,则可以默认设置为True,如果没有False
  5. 如果Exit Sub,您是否需要False还是继续?
  6. 什么是arrRecords?它来自哪里?

代码:

Option Explicit

Sub test()
    If IsEmpty(arrRecords) Then '<> vbNullString   ''if string
        GoTo Get_Out
    Else
        PrintArray arrRecords, Y, Lastrecord, 1  
        'Exit Sub '<== What happens here? Otherwise you still hit Get_Out
    End If

Get_Out:

End Sub
相关问题