Naming Conventions

VBA programs can quickly become quite complicated so we can use all the help we can in trying to make them as readable as possible.
Often as time passes and we move on to other projects the original ideas behind the program fade and we rely on readable code to refresh our memory.
An easy way to make programs more readable is to use a consistent naming convention throughout.
This should not only apply to variables but also to constants, procedures and all other items.


Constants

All Capitals

Const m_iMODULELEVEL As Integer = 100 
Public Const g_iPROJECTLEVEL As Integer = 100

Public Sub MySubroutine()
Const sPROCEDURELEVEL As String = "text"

Variables (Local)

Hungarian
Variables must begin with a letter or an underscore
Variables are prefixed with an abbreviation that indicates its data type.
For example prefixing a variable with "s" indicates that it is a string.
For a list of all the common prefixes, please refer to the Data Types section.

Dim sMyString As String 
Dim iMyNumber As Integer

Variables (Module Level)

PascalCase
Initial uppercase for variable names
No data type prefix to help distinguish them

Dim VariableName As Object 

Subroutines

PascalCase

Sub DoSomething() 
End Sub

Functions

PascalCase

Function ReturnSomething() 
End Function

Classes

camelCase
Initial lowercase for classes

Dim oMyClass As myClass 

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext