Tutorial by Examples

There are multiple ways to populate an array. Directly 'one-dimensional Dim arrayDirect1D(2) As String arrayDirect(0) = "A" arrayDirect(1) = "B" arrayDirect(2) = "C" 'multi-dimensional (in this case 3D) Dim arrayDirectMulti(1, 1, 2) arrayDirectMulti(0, 0, 0...
Due to not being Excel-VBA exclusive contents this Example has been moved to VBA documentation. Link: Dynamic Arrays (Array Resizing and Dynamic Handling)
Due to not being Excel-VBA exclusive contents this Example has been moved to VBA documentation. Link: Jagged Arrays (Arrays of Arrays)
A common problem might be trying to iterate over Array which has no values in it. For example: Dim myArray() As Integer For i = 0 To UBound(myArray) 'Will result in a "Subscript Out of Range" error To avoid this issue, and to check if an Array contains elements, use this oneliner: If...
Sub Array_clarity() Dim arr() As Variant 'creates an empty array Dim x As Long Dim y As Long x = Range("A1", Range("A1").End(xlDown)).Cells.Count y = Range("A1", Range("A1").End(xlToRight)).Cells.Count ReDim arr(0 To x, 0 To y) 'fixing the size of...

Page 1 of 1