The VBA LBound Function

Related Function:
VBA UBound

Description

The VBA LBound function returns the lowest subscript for a dimension of a supplied array.

The syntax of the function is:

LBound( ArrayName, [Dimension] )

Where the function arguments are:

ArrayName-

The array for which you want to find the lowest subscript.

[Dimension]-

An optional integer, specifying the dimension of the array, for which you require the lowest subscript.

If [Dimension] is omitted, it takes on the default value 1.


VBA LBound Function Examples

Example 1 - One-Dimensional Array

' Return the lowest subscript of a one-dimensional array.
Dim prices(0 to 10) As Double
Dim pricesLB As Integer
pricesLB = LBound( prices )
' Now the integer pricesLB has the value 0.

After running the above VBA code, the variable pricesLB has the value 0.


Example 2 - Two-Dimensional Array

' Return the lowest subscripts of each dimension a 2-d array.
Dim costs(0 to 10, 1 to 100) As Double
Dim costsLB1 As Integer
Dim costsLB2 As Integer
costsLB1 = LBound( costs, 1 )
costsLB2 = LBound( costs, 2 )
' Now, costsLB1 = 0 and costsLB2 = 1.

After running the above VBA code, the variable costsLB1 has the value 0 and the variable costsLB2 has the value 1.