Consulting

Results 1 to 2 of 2

Thread: ReDim a type

  1. #1
    VBAX Newbie
    Joined
    Mar 2012
    Posts
    1
    Location

    ReDim a type

    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 hat just produces an error.
    Any Ideas?

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    7,398
    Location
    try this and see


    [vba]
    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
    [/vba]

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •