Results 1 to 2 of 2

Thread: Array Help

  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Hi all,

    I am trying to populate an array fill with values, I have a parsed text string that I would like to store with 13 seperate values. I would like the array to be dynamic, the reason for this is, I want to be able to fire it off to the worksheet, or a database.

    I need help declaring the array,

    Is the statement "Dim mydarray(x,13) as variant" correct?

    Thanks,
    Darryl.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to be able to dynamically resize the array, be aware that you can only resize the second dimension in your code:

    Code:
    Sub Demo()
        Dim MyArr() As Variant
        Dim lRowCt As Long
        Dim lColCt As Long
        ReDim MyArr(1 To 10, 1 To 2)
        'now fill array
        For lRowCt = 1 To 10
            For lColCt = 1 To 100
                If UBound(MyArr, 2) < lColCt Then
                    'we need to resize the array and keep its values
                    'We double the size each time to avoid having to do
                    'this very ofter
                    ReDim Preserve MyArr(1 To 10, 1 To UBound(MyArr, 2) * 2)
                End If
                MyArr(lRowCt, lColCt) = lRowCt * lColCt
            Next
        Next
        'now throw away the extraeneous columns
        ReDim Preserve MyArr(1 To 10, 1 To lColCt - 1)
    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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