2
Contributors
1
Reply
5
Views
9 Years
Discussion Span
Last Post by shasur
0

You can do that by Redim statement

Sub Array_Dimensioning()
Dim arTemp() As Integer     ' Preserved Array
Dim arTemp1() As Integer    ' Array without Preserve
ReDim Preserve arTemp(1, 1)
ReDim arTemp1(1, 1)
arTemp(1, 1) = 1
ReDim Preserve arTemp(1, 2)
arTemp(1, 2) = 2
ReDim Preserve arTemp(1, 3)
arTemp(1, 3) = 3
ReDim Preserve arTemp(2, 3)
ReDim arTemp1(2, 1)
End Sub

If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The arTemp falls under this category. However, arTemp1 you can redimension the array in any dimension, but the contents will be erased with every Redim statement

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.