Hi, pedie.
Redim is usually used for resizing an array.
For example, if you had a array declared in the beginning of a Sub or w/e.
Error:
Code:
Sub Test()
Dim strData() As String
strData(2) = "Hi"
MsgBox strData(2)
End Sub
and you want to store a value in index:=2 with Option Explicit on.
You will be unable to assign value to it because it doesn't have a specified range array.
However, when you do have a fixed array
Fixed:
Code:
Sub Test2()
Dim strData(0 To 5) As String
strData(2) = "Hi"
MsgBox strData(2)
End Sub
Altho you will be able to declare it and assign values to it, you will be unable to append more data at the end of your array without declaring a new array.
So, a method came up and it was the
ReDim statement.
ReDim allows you to resize the array or newly declare an existing variable.
Code:
Sub Test3()
Dim strData$()
ReDim strData$(0 To 6)
strData(6) = "Hi"
End Sub
Moreover, there is one more option about
ReDim you will need to learn and that's
Preserve.
Because ReDimming does not store previous values stored, you will need to use
Preserve if you want the original values still stored in their own places.
Code:
ReDim Preserve strData$(0 To 6)
Hope it helps.