## Excel VBA LBound

LBound in VBAstands for “Lower Bound” i.e. it will extract the lowest number of an array. For example, if the array says “Dim ArrayCount (2 to 10) as String” then using LBound function we can find the least number of the array length i.e. 2.

Below is the syntax of the LBound function. It is very simple and easy, it has only two parameters to it.

Lbound (Array name [, dimension])

**Array Name:**This is the first argument. For this parameter, we need to specify the name of the array which is used to define the array.**[Dimension]:**If the array is a single dimension then this is not required, by default it takes one or else we need to supply the dimension number.

So, using LBound function we can find the minimum length of an array.

### How to use LBound Function?

#### Example #1

For an example look at the below code.

**Code:**

Sub LBound_Example1() Dim Count(2 To 5) As Integer MsgBox LBound(Count) End Sub

In the above code, we have defined the array as integer and size of the array as 2 to 5. Next, we have assigned the VBA message box to show the lowest length of the array by using the LBound function.

When we run the code we will get the below result in a message box.

**Output:**

Since our array starting from 2, the LBound function determines the lowest length of the array as 2.

#### Example #2

Now, look at the below code.

**Code:**

Sub LBound_Example2() Dim Count(5) As Integer MsgBox LBound(Count) End Sub

In the above we have not decided the lowest limit rather we just supplied the array length as 5, now let’s run the code and see the lowest length of the value.

**Output:**

It has returned the result as 0 because when we don’t decide the start and endpoint of an array rather provide the static number, for example, “Count (5) i.e. in this case array value starting from 0 not from 1. So we can store totally 6 values in it now.

Count (0), Count(1), Count(2), Count(3), Count(4), Count(5).

#### Example #3

Now we will use data range and decide the lower bound from the range of data. For an example look at the below data image.

From this range, we will decide the lowest and highest row size.

First, define the variable as a variant.

**Code:**

Sub LBound_Example3() Dim Rng As Variant End Sub

For this “Rng” variant variable set the range reference value as “Range (“B2: B5”).Value”.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("B2:B5").Value End Sub

For this range, we will find the lowest and highest array length. Open the message box and LBound function and supply the variable name.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("B2:B5").Value MsgBox LBound(Rng) End Sub

Now run the VBA code and see the lowest value from the length.

**Output:**

Now change the variable reference from B2: B5 to A2: B5.

For this range, we will find the lower bound and upper bound values.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("A2:B5").Value End Sub

Since we have more than one dimension array we need to supply the dimension number as well.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("A2:B5").Value MsgBox LBound(Rng, 1) End Sub

To find the first column first lower bound above code will help, similarly to find the upper bound in this first column below code will help.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("A2:B5").Value MsgBox LBound(Rng, 1) & vbNewLine & UBound(Rng, 1) End Sub

This will find the first column lower length and upper length. Similarly in the next line write one more message box but this time change the dimension from 1 to 2.

**Code:**

Sub LBound_Example3() Dim Rng As Variant Rng = Range("A2:B5").Value MsgBox LBound(Rng, 1) & vbNewLine & UBound(Rng, 1) MsgBox LBound(Rng, 2) & vbNewLine & UBound(Rng, 2) End Sub

Run the code and see the result in the message box.

**Output:**

For the first dimension lower bound is 1 and the upper bound is 4.

Click on “Ok” to get the next dimension limits.

**Output:**

For the second dimension lower limit is 1 and the upper limit is 2.

### Things to Remember here

- LBound function returns the minimum length from the array.
- When the array length static i.e. single number then array always starts from the number 0 not from 1.
- In the case of a multi-dimensional array, we need to specify the dimension number.

### Recommended Articles

This has been a guide to VBA LBound. Here we discuss how to use vba LBound function to find the least number of the array length in excel along with practical examples and downloadable templates. Below are some useful articles related to VBA –

- VBA StrComp Function
- VBA Square Root Examples
- SendKeys Method in VBA
- VBA Randomize
- RoundUp in VBA
- UBOUND in VBA
- ArrayList in VBA
- InputBox in VBA