Excel VBA LBound Function

Excel VBA LBound Function: The LBound function in VBA returns the lowest subscript for the specified dimension in the given array.

Syntax

LBound (ArrayName, [Dimension])

Parameter

ArrayName (required) – This parameter represents an array for which you want to find the lowest subscript.

Dimension (optional) – This parameter specifies the dimension of the array, for which you require the lowest subscript. By default, this parameter is set to 1.

Return

This function returns the lowest subscript for the specified dimension in the given array.

Example 1

Sub LBoundFunction_Example1()
 ' Returning the lowest subscript for a 1-D array.
 Dim Array_Val(0 To 9) As Integer
 Dim LB_val As Integer
 LB_val = LBound(Array_Val)
 ' The integer LB_val will return a value equal to 0.
 Cells(1, 1).Value = LB_val
 End Sub 

Output

0

VBA LBound Function

Example 2

Sub LBoundFunction_Example2()
 ' Returning the lowest subscript for a 2-D array.
 Dim Array_val(1 To 10, 10 To 20) As Double
 Dim LB_val1 As Double
 Dim LB_val2 As Double
 LB_val1 = LBound(Array_val, 1)
 LB_val2 = LBound(Array_val, 2) 
 ' The integer LB_val1 will return a value equal to 1.
 Cells(1, 1).Value = LB_val1
 ' The integer LB_val2 will return a value equal to 10.
 Cells(2, 1).Value = LB_val2
 End Sub 

Output

1

10

VBA LBound Function