Excel VBA: General UserForm VBA Coding Practices Part 3. Excel VBA 2 Lesson 12

 

HOME | Back to index  <Previous | Next> Buy the complete Excel course, Including VBA & Workbook examples for only $9.95 | Ask a question?

Example Coding Standards for use with UserForm lessons.

  1. Modules begin with Option Explicit

  2. Unofficial Version Control

    1. Modules begin with the modified date in a comment

    2. Macros begin with a comment with version and modified date on the Sub declaration line if it is short

    3. Macros longer than a few lines have the macro name repeated in a comment on the End Sub line

  3. Macro names begin with a lower case letter if parameters are required

  4. Variables declared at the top of a module reduce passed parameters

  5. Variable names preferably begin with a lower case letter and also have a number or capital letter, to help differentiate from Excel names

  6. Indenting

    1. Subs, Functions, intentional code comments, and With and Loop control structures are indented 4

    2. "_" line extensions are indented 2

    3. Code statements temporarily commented out are not indented

    4. Debug.Print statements; Not are

  7. Dim shorthand (helps avoid declaration and comparison problems)

    1. varName% same as varName As Integer

    2. varName& same as varName As Long

    3. varName$ same as varName As String

HOME | Back to index  <Previous | Next> Buy the complete Excel course, Including VBA & Workbook examples for only $9.95 | Ask a question?

 

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid.com is in no way associated with Microsoft.

OzGrid.com accepts no responsibility for any adverse affect that may result from undertaking our training.