Return to VBA Code Examples

VBA UBound & LBound Functions

UBound Description

Returns the highest subscript for a dimension of an array.

Simple UBound Examples

Result: 10

UBound Syntax

The UBound function contains 2 arguments:

ArrayName: Name of Array variable.

Dimension: [Optional] Integer indicating which dimension’s lower bound is returned. Use 1 for the first dimension, 2 for the second, etc. 1 if ommitted.

Examples of Excel VBA UBound Function

Result: 5, 5, 8, 25

LBound Description

Returns the lowest subscript for a dimension of an array.

Simple LBound Examples

Result: 3

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! automacro

Learn More!!

LBound Syntax

The LBound function contains 2 arguments:

ArrayName: Name of Array variable.

Dimension: [Optional] Integer indicating which dimension’s lower bound is returned. Use 1 for the first dimension, 2 for the second, etc. 1 if ommitted.

Examples of Excel VBA LBound Function

Result: 1, 1, 4, 12