HomeVBA Functions LIST (Category Wise)How to use the VBA UBOUND Function (Syntax + Example)

What is VBA UBOUND Function

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.

how to use it

To use VBA's UBOUND function you need to understand its syntax and arguments:


UBound(ArrayName, [Dimension])


  • 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 use UBOUND Function in VBA

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

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.

Related Functions

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.