Labels
- Last UpdatedJul 18, 2023
- 1 minute read
Labels can be used to divide a large VBA function or subroutine into logical sub-sections of code script. Labels are often used in association with the GoTo statement. All of the VBA script following the label and extending through to another label, or to the end of the function or subroutine containing the label, is regarded as belonging to that label. Or more appropriately, the label is said to identify, or be attached to, that particular section of VBA script.
Labels must begin with a letter, be no longer than 40 characters, and cannot be a reserved word. Labels must terminate with the colon character (:). Label names can only contain the letters 'A' to 'Z' and 'a' to 'z', the underscore '_' character, and the digits '0' to '9'. Label names cannot contain the space character.
Label names (once declared), become a keyword in VBA. Like most keywords in VBA, label names are not case sensitive. For example, all of the following label examples are treated identically in VBA:
label1:
Label1:
LABEL1:
Note: Labels as used in VBA are not the same as labels used in Plant SCADA.