Indentation and White Space
White space is ignored in VBA and the editor will automatically discard any extra spaces.
If you type
myInteger = 6
This will be automatically changed to
myInteger = 6
The exception is when whitespace is included within double quotes, as part of a string.
You can use the Tab key to indent your lines of code that logically belong together to make the code easier to read.
The tab key should be used instead of pressing the spacebar multiple times.
You can also use (Shift + Tab) to "unindent" your lines of code.
You can change the default tab size from the (Tools > Options)(Editor tab).
Function DoSomething() As Integer
Dim iNumber As Integer
For iNumber = 1 to 5
DoSomething = DoSomething + iNumber
The Indent and Outdent buttons on the Edit toolbar can also be used on blocks of code.
|Indent - Shifts all the lines (in the current block) to the next tab stop.|
|Outdent - Shifts all the lines (in the current block) to the previous tab stop.|
All code should be consistently indented with line spaces where appropriate.
Different parts of the code should be separated by using a blank line.
Indentation should be used to highlight the block structure and control statements.
Tabs must be used for indentation (4 which is the default).
One statement per line. Avoid putting multiple statements on the same line (ie using :). This makes debugging more difficult as the project might have to be reset after making dynamic changes. The only exception to this is if you are initialising a simple variable.
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext