The colon operator :
is a statement delimiter in VBA.
However, does anyone has a clue why the first three examples work and the fourth (when uncommented) produces an error?
Option Explicit
Public Sub TestMe()
If 1 = 1 Then: Debug.Print 1
If 2 = 2 Then Debug.Print 2
If 3 = 3 Then:
Debug.Print 3
' Gives error:
' If 4 = 4 Then
' Debug.Print 4
'Other Examples, from the comments and the answers:
:::::::::::::::::::::::::::: '<-- This seems to be ok
If 5 = 5 Then Debug.Print "5a"::: Debug.Print "5b"
If 6 = 0 Then Debug.Print "6a"::: Debug.Print "6b"
If 7 = 0 Then:
Debug.Print 7 ' Does not have anything to do with the condition...
If 8 = 0 Then Debug.Print "8a"::: Debug.Print "8b" Else Debug.Print "8c"
End Sub
See Question&Answers more detail:os