Redim and Redim Preserve Dynamic Arrays Explained in Excel VBA - Code Included

Опубликовано: 15 Октябрь 2024
на канале: EverydayVBA
12,376
79

Grab the Free VBA Quick Reference Guide
https://www.chrisjterrell.com/excel-v...
In this video we go over how to use ReDim and Redim Preserve.

Redim is a way to resize a Dynamic array and delete the contents. Redim Preserve will resize dynamic arrays and keep the data.

Dynamic Arrays are different than fixt arrays because they are not defined when they are declared

NOTE: Fixed arrays cannot be ReDimed

CODE:

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)

End Sub