以下是我在VBA中的代码:
Sub Hamza_Starting_to_Learn()
Dim Hamza_Variable As Long
Hamza_Variable = 7
If Hamza_Variable = 7 Then
MsgBox Hamza_Variable & " Is da bomb"
Elself Hamza_Variable > 7 Then
MsgBox Hamza_Variable & " Is da bigger bomb"
Else
MsgBox Hamza_Variable & "We got ourselves a problem here bro"
End If
它不断给出编译错误"语句结束"在以下行:
Elself Hamza_Variable > 7 Then
突出显示Then
并提供此错误。
答案 0 :(得分:1)
既然你开始学习,也许你应该用Select Case
声明来获得familair:
Option Explicit
Sub Hamza_Starting_to_Learn()
Dim Hamza_Variable As Long
Hamza_Variable = 7
Select Case Hamza_Variable
Case 7
MsgBox Hamza_Variable & " Is da bomb"
Case Is > 7
MsgBox Hamza_Variable & " Is da bigger bomb"
Case Else
MsgBox Hamza_Variable & "We got ourselves a problem here bro"
End Select
End Sub
答案 1 :(得分:0)
试试这个:
Sub Hamza_Starting_to_Learn()
Dim Hamza_Variable As Long
Hamza_Variable = 7
If (Hamza_Variable = 7) Then
MsgBox Hamza_Variable & " Is da bomb"
ElseIf Hamza_Variable > 7 Then
MsgBox Hamza_Variable & " Is da bigger bomb"
Else
MsgBox Hamza_Variable & "We got ourselves a problem here bro"
End If
End Sub
您没有使用End Sub
答案 2 :(得分:0)
在原始代码中,您在收到错误的行中写了Elself
而不是ElseIf
(请注意拼写错误l
和I
)。这可能会让VBA感到困惑,反过来又会给你带来误导性的错误信息。
(感觉不是太糟糕。Other people have also had problems distinguishing these two letters in some monospace fonts before.)