+ Reply to Thread
Results 1 to 6 of 6

arrays in VBA

  1. #1
    Registered User
    Join Date
    07-31-2007
    Posts
    35

    arrays in VBA

    Is there a simple way to insert a bunch of 1-D arrays into a 2-D array without cycling through every single cell? I want to just lump in entire rows or columns (1-D arrays) at a time and not cycle through the individual cells if I don't have to.

    Thanks

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    The quickest easiest way to populate an array from a sheet is

    Please Login or Register  to view this content.
    change rows & columns to suit
    this gives a 1 dimension array

    If you need a 2 dimenstion array with the 2nd dimention blank have your data in column A & column B blank

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524
    Quote Originally Posted by mudraker
    The quickest easiest way to populate an array from a sheet is

    Please Login or Register  to view this content.
    change rows & columns to suit
    this gives a 1 dimension array
    No
    When you convert range value to vb array, it will be always 1 based 2D array, no exception.
    And if you want blank...
    Please Login or Register  to view this content.
    will give you Col.A value & same length of blank col.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    jindon

    Thanks for pointing out my error that my code gives a 1 dimension array which is incorrect.


    This line of your code will cause incorrect
    Please Login or Register  to view this content.
    It should be
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Some links on arrays

    http://puremis.net/excel/code/053.shtml

    http://www.dailydoseofexcel.com/arch...nge-using-vba/

    http://www.exceltip.com/st/Array_var...Excel/509.html

    Variant array to hold two arrays. Step throught this sample subroutine with the immediate window open

    Please Login or Register  to view this content.



    VBA Noob
    Last edited by VBA Noob; 10-28-2007 at 12:19 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  6. #6
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267

    Addendum to Jindon's comment

    To qualify Jindon's observation that "when you convert range value to vb array, it will be always 1 based 2D array, no exception", it must however be noted that when range transposition is involved, you can sort of convert range values to a 1D Array as the following codes illustrate.

    1. The simple transposition of one-column range:

    Please Login or Register  to view this content.
    2. The double transposition scenarios

    Please Login or Register  to view this content.
    There is no doubt that it is this property of Array dimension changing by transposition from one-column range (2D) to putatively a one-row range (ID) that gives the illusion that "horizontal single row range" gives rise to a 1-D Array.

    Outside the context of transposition, Jindon is perfectly right. I was only a bit uneasy about the rider "no exception". Again, as he pointed out, Variant arrays are by definition typecast to Base1.
    Last edited by Myles; 10-31-2007 at 12:45 AM.
    HTH
    Myles

    ...constantly looking for the smoother pebble while the whole ocean of truth lies before me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1