The LBound and UBound functions return whole numbers that indicate the lower bound and upper bound indices of an array. : Array Function « Data Type « VBA / Excel / Access / Word






The LBound and UBound functions return whole numbers that indicate the lower bound and upper bound indices of an array.

 
Sub FunCities2()
    Dim cities(1 To 5) As String
    cities(1) = "Las Vegas"
    cities(2) = "Orlando"
    cities(3) = "Atlantic City"
    cities(4) = "New York"
    cities(5) = "San Francisco"

    MsgBox cities(1) & Chr(13) & cities(2) & Chr(13) _
        & cities(3) & Chr(13) & cities(4) & Chr(13) _
        & cities(5)

    MsgBox "The lower bound: " & LBound(cities) & Chr(13) _
        & "The upper bound: " & UBound(cities)
End Sub

 








Related examples in the same category

1.Using the Array Function
2.avoids the error "Subscript out of range"
3.Use IsArray function to check if a variable is an array