VBA UBOUND Function (Syntax + Example)

Last Updated: March 24, 2024
puneet-gogia-excel-champs

- Written by Puneet

The VBA UBOUND function is listed under the array category of VBA functions. When you use it in a VBA code, it can return the highest subscript for a dimension of the array supplied. In simple words, it helps you to find the upper limit of an array, by returning the highest value in the result.

Syntax

UBound(ArrayName, [Dimension])

Arguments

  • ArrayName: The array for which you want to find the highest subscript.
  • [Dimension]: An integer to define the dimension of the array (This is an optional argument and if omitted VBA takes 1 by default).

Example

To practically understand how to use the VBA UBOUND function, you need to go through the below example where we have written a vba code by using it:

example-vba-ubound-function
Sub example_UBOUND()
Dim myAry(0 To 1100) As Double
Range("A1").Value = UBound(myAry, 1)
End Sub

In the above code, we have used the UBOUND to get the highest subscript for a dimension of the array “myAry” and it has returned 1100 in the result which is the highest value from 0 to 1100.