PDA

View Full Version : Sleeper: ReDim a type



athom
03-06-2012, 05:40 AM
Hi there,
I'm using type to store data in my VBA code. I start with the usual declaration:

Type BeamType
TotNo As Long
No(200) As Long
End Type
I then assign a variable to this type:

Dim Beams As BeamType
How do I change the array size in my code though, I tried ReDim like:

ReDim Preserve Beams.No(1 To 20) As Long
But that just produces an error.
Any Ideas?

Paul_Hossler
03-06-2012, 06:57 PM
try this and see


Option Explicit

Type BeamType
TotNo As Long
No() As Long ' --------
End Type

Sub test()
Dim i As Long
Dim Beams As BeamType
ReDim Preserve Beams.No(1 To 20)
For i = 1 To 20
Beams.No(i) = 10 * i
Next i
For i = 1 To 20
Debug.Print Beams.No(i)
Next i
ReDim Preserve Beams.No(1 To 30)
For i = 1 To 30
Beams.No(i) = 10 * i + 1
Next i
For i = 1 To 23
Debug.Print Beams.No(i)
Next i
End Sub


Paul

PS. Although the title of the forum is "SUMPRODUCT and Array Ffunctions", it's refering to the sort of worksheet functions that you enter using Ctrl-Shift-Enter.

The main Excel forum will provide better answers