'Else keyword is separated from its If statement because it’s in a different scope. This separates the If statement and the Else keyword and causes the error to show up. In the following example, If Thenis followed by the beginning of a Forloop followed by the Elsekeyword. The correct way to have multiple scopes work with each other is to have one totally placed inside the other. A problem occurs if you overlap scopes in a way that causes one to be partially placed inside the other. Other scopes can also exist in the code due to the existence of loops such as For Next loop, Do Until loop or For Each Next loop.Ī scope exists when a logical statement requires multiple keywords to indicate the start and end points of the statement. But if we look closer, we will see that the scope of the If statement is different from that of the else statement.Įverything between the If statement and the End If keyword belongs to the scope of this If statement. The problem might not be apparent at first glance. You might be surprised that you are getting the error when you already have the If statement present in the code and placed prior to the Else keyword and written correctly. End If Example 2: Else statement is inside a loop and If statement is outside
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |