Results 1 to 15 of 15

Thread: How to read data from a worksheet into an array in a module?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,446
    Location
    Indeed, and you also didn't account for the Option Base. By using

    [vba]

    ReDim Arr(R.Rows.Count, R.Columns.Count)
    [/vba]

    you are effectively saying

    [vba]

    ReDim Arr('option base' To R.Rows.Count, 'option base ' To R.Columns.Count)
    [/vba]

    so if you have Option Base 0 as I do that means

    [vba]

    ReDim Arr(0 To R.Rows.Count, 0 To R.Columns.Count)
    [/vba]

    or a 4x3 array, bigger than is necessary, Arr(0), Arr(0,0), Arr(0,1) and Arr(0,2) and so on.

    When you load the array, it gets redimensioned again to

    [vba]

    ReDim Arr(1 To R.Rows.Count, 1 To R.Columns.Count)
    [/vba]

    regardless of Option Base, or an array of 3x2, Arr(1), Arr(1,1), Arr(1,2), etc.
    Last edited by Bob Phillips; 03-12-2008 at 03:34 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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