VBA – How the colon `:` works in VBA code with condition

I think the confusion comes from 3. We’d think that 3 and 4 should behave the same. In fact, 3 is equivalent to this:

If 3 = 3 Then: (do nothing) 'an empty statement
   Debug.Print 3 ' <-- This will be executed regardless of the previous If condition

To see it, change 3 into this:

If 3 = 0 Then:
    Debug.Print 3 '<-- 3 will be printed! ;)

In conclusion, yes, the : is indeed to merge many statements on a single line

Good job @Vityata !!! 🙂

Leave a Comment