Arrays Ubound and Lbound Explained in Excel VBA - Code Inlcuded

Опубликовано: 15 Октябрь 2024
на канале: EverydayVBA
13,673
74

Grab the Free VBA Quick Reference Guide
https://www.chrisjterrell.com/excel-v...
In this video we explain the Ubound (Upper bound) and LBound (Lower bound). These are used to identify the size or dimensions of an array. They return an integer or index of a particular dimension of an array. In this video we show examples of how to use the Ubound ad Lbound on a 1 and 2 dimensional array

NOTE: Debug.print displays or prints the data in the immediate window. To show this the immediate window go to View - immediate window

Code included

Sub array_code()

Dim oarray(0 To 3)
oarray(1) = "This"
oarray(2) = "is"
oarray(3) = "An Array"

'Dim earray(1 To 3)
'ReDim earray(1 To 4)
Dim darray()

ReDim darray(1 To 3)
darray(1) = "Test"

ReDim Preserve darray(1 To 1)

ReDim darray(1 To 1)
Dim uarray(1 To 20, 1 To 10)
Dim larray(10 To 20, 5 To 10)

Debug.Print UBound(uarray)
Debug.Print UBound(uarray, 2)
Debug.Print LBound(larray, 1)
Debug.Print LBound(larray, 2)
Debug.Print UBound(oarray)
Debug.Print LBound(oarray)

End Sub