Results 1 to 6 of 6

Thread: Excel - VBA - Array and sheet *Resolved*

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Excel - VBA - Array and sheet *Resolved*

    Hi,

    I know that you can put an array into a range and it posts in it beautifully. And Quickly.

    Now how do you do the opposite ad get a range into an array of variant??

    I tried the opposite :
    VB Code:
    1. Redim aryTitles(21)
    2. aryTitles() = shtSrc.Range(shtSrc.Cells(1, 1), shtSrc.Cells(1, 21))
    This doesn't work and the array is reset to 0 elements.

    Any ideas?


    Vince
    Last edited by Ecniv; Apr 20th, 2004 at 09:25 AM.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    You need to use a variant to store the returned values, rather than an array. eg:
    VB Code:
    1. Dim aryTitles
    2. aryTitles = shtSrc.Range(shtSrc.Cells(1, 1), shtSrc.Cells(1, 21))

  3. #3

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Ahh..

    Just one variable that is variant... not a redimmed array of variant?

    Is this variant variable like an array or do I need to change it into an array?


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Yep.. this way you get a variant containing an array (no need for any conversion), rather than an array or variants.

    This is needed as you cant directly assign all values to an array in one statement (but you can set a variant to contain an array).

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    oh, and by the way (in case you dont know)... the array it returns is dimmed as follows:

    (1 to <num rows> , 1 to <num cols>)

  6. #6

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Ta

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width