Syntax


Automatic Formatting

The Visual Basic Editor will perform a few actions for you automatically to improve the readability of your code.
Spaces between any operators will be added for you.

2+3   'before  
2 + 3 'after

Any keywords, properties or methods will start with a capital letter

inumber=activesheet.range("B2").value  'before  
inumber = Activesheet.Range("B2").Value 'after

The case of variable names will be changed to match how the variable was last entered.


For example if you have a variable called "inumber" (all lowercase) and then you type the variable in uppercase "iNUMBER" all other occurrences of this variable will be changed.
An exception to this is if the variable is declared using the DIM statement. In this case the variable will always appear as it has been declared.
Variables are not case sensitive.


Undoing Your Mistakes

You can easily undo any changes you make to your code by selecting (Edit > Undo) or using the shortcut key (Alt + Backspace).
You can also easily redo changes by using (Edit > Redo) or by using the shortcut key (Ctrl + Z).
The undo and the redo functions are multi-level and have a maximum of 20 operations.


Shortcut Keys

(Ctrl + Space) - Displays the drop-down list of auto-list intellisense.


All references to external VBA Projects should be made using late binding. This is to prevent any problems from different versions that may exist
The most popular notation is Pascal Notation (initial uppercase)
Variables cannot be declared and initialised all on the same line.


Important

Try and have IF, THEN and END IF blocks on separate lines
Try and avoid having any "hanging ELSE statements" (e.g. do not include an else unless there are statements to be executed)
Try and use the Select-Case if appropriate
Only use the With-End with when appropriate (this slows down debugging and is not necessary for one or two statements).
When using any of the built-in functions always include the brackets or even better always prefix with VBA (e.g. VBA.Date() )
It is good programming practice to try and declare as many symbolic constants as possible at the beginning of your program. These are often placed in the Declarations sections of a code module.


© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

Next