How can I prevent the VBA editor from removing internal spaces?

I believe alignment of identifiers, operators, etc. in my code greatly improves readability. Errors just jump off the screen before I ever compile or run the code. However, the VBA editor removes the extra spaces, destroying my alignment. For example, I am trying to enter several lines as follows:

something         = "a" & CStr(iRow1)  'Colm A = Something useful
somethingElse     = "b" & CStr(iRow1)  'Colm B = Something else
dunno             = "c" & CStr(iRow1)  'Colm C = Don't know what this is
whatEver          = "d" & CStr(iRow1)  'Colm D = whatever you want
aVar              = "e" & CStr(iRow1)  'Colm E = A variable
xOrY              = "f" & CStr(iRow1)  'Colm F = Might be X or Y
aLongVariableName = "g" & CStr(iRow1)  'Colm G = Long variable name

but I get the following:

something = "a" & CStr(iRow1)                      'Colm A = Something useful
somethingElse = "b" & CStr(iRow1)          'Colm B = Something else
dunno = "c" & CStr(iRow1)                                  'Colm C = Don't know what this is
whatEver = "d" & CStr(iRow1)                         'Colm D = whatever you want
aVar = "e" & CStr(iRow1)                            'Colm E = A variable
xOrY = "f" & CStr(iRow1)                            'Colm F = Might be X or Y
aLongVariableName = "f" & CStr(iRow1)  'Colm G = Long variable name

This is much less readable. Even the comments are not aligned. Note how easy it would be to identify jRow among iRow in the first block compared to the second. And did you notice an error in the last line of misaligned code ("f" instead of "g")? Not so easy to notice without alignment.

So, how can I prevent the VBA editor from twisting my alignment by eating extra spaces?

+4
3

VBE (VBA IDE) .

.

: . , , .


Fine. ?

!

iRow jRow, , : playerRow teamRow.

, , ? ? , , ?

, , , , ; /. - .

, : - , , , .

/ , , , , , , " " - - .

Dim aLongVariableName As String                'declaration
aLongVariableName = "f" & CStr(iRow1)          'assignment
DoSomethingInvolvingColumnG aLongVariableName  'usage
+8
        something = "a" & CStr(iRow1)  'Colm A = Something useful
    somethingElse = "b" & CStr(iRow1)  'Colm B = Something else
            dunno = "c" & CStr(iRow1)  'Colm C = Don't know what this is
         whatEver = "d" & CStr(iRow1)  'Colm D = whatever you want
             aVar = "e" & CStr(iRow1)  'Colm E = A variable
             xOrY = "f" & CStr(iRow1)  'Colm F = Might be X or Y
aLongVariableName = "g" & CStr(iRow1)  'Colm G = Long variable name
+4

You can use the continuation character "_" for "fudge" as follows:

something = _
                    "a" & CStr(iRow1)          'Colm A = Something useful
somethingElse = _
                    "b" & CStr(iRow1)          'Colm B = Something else
dunno = _
                    "c" & CStr(iRow1)          'Colm C = Don't know what This is
whatEver = _
                    "d" & CStr(iRow1)          'Colm D = whatever you want
aVar = "e" _
                        & CStr(iRow1)          'Colm E = A variable
xOrY = _
                    "f" & CStr(iRow1)          'Colm F = Might be X or Y
aLongVariableName = _
                    "f" & CStr(iRow1)          'Colm G = Long variable name
+1
source

All Articles