SurreyNick
Member
- Local time
- Today, 09:58
- Joined
- Feb 12, 2020
- Messages
- 127
I'm interested to understand why the syntax of this very simple IF statement works in example A but not in example B. Even though both examples require only one resulting action Example B requires an End If block to work, whist Example A doesn't. The only difference is that in Example B the Debug.Print command is on a new line (absence of indenting is deliberate to illustrate the only difference is the carriage return). Could someone explain? Thank you.
Code:
Sub SimpleIFa()
'This code works without an End If block
Dim Rating As Long
Rating = 1
If Rating = 0 Then Debug.Print "Rejected. Rating below minimum required"
If Rating = 1 Then Debug.Print "Approved. Rating above minimum required"
End Sub
Sub SimpleIFb()
'This code will only work if an End If block is included
Dim Rating As Long
Rating = 1
If Rating = 0 Then
Debug.Print "Rejected. Rating below minimum required"
If Rating = 1 Then
Debug.Print "Approved. Rating above minimum required"
End Sub