Consulting

Results 1 to 5 of 5

Thread: Solved: Filling a simple array

  1. #1
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    144
    Location

    Solved: Filling a simple array

    Howdy,

    Just wondering if there is any difference between 2 techniques in filling an array with 10 different elements:

     TheArray = Array("Zoo", "Farm", "Paddock", "Sheep", "Cow", "Bird", ?Mice", "Chicken", "Fence", "Post")

     TheArray = Range("A1:A10").Value

    Same 10 elements are stored in range A1:A10

    Thanks & regards

    KP

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Flexibility and ease of use.

    Consider using a dynamic range name for your Array range
    eg Add the range "Data" using Insert/Names/Define and the formula =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1)
    [vba]TheArray = Range("Data").Value[/vba] This will adjust itself to the length of the data records (no blanks)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The first is a one dimensional array, the second is two dimensional.
    ____________________________________________
    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

  4. #4
    VBAX Contributor
    Joined
    Aug 2006
    Location
    Hampshire, UK
    Posts
    140
    Location
    The lower bound (of the first dimension) of the first array will depend on your option base setting (default 0) whereas the second will always be 1.

    Richard

  5. #5
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    144
    Location
    Thanks guys for your prompt input. I'll read up more on 1 & 2 dimensional arrays on how to use them.

    Have a nice day.

    Regards


    KP

Posting Permissions

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