Share via

VBA - Question on Array

Anonymous
2015-12-14T19:36:30+00:00

When using Excel VBA to create macros, is it possible to create a single 3-dimensional array instead of two 2-dimensional arrays then copy a selected range.value into the 3-dimensional array by only selecting the 1^st^ array dimension instead of copying a selected range.value into each of the 2 dimensional arrays?

Instead of:

  • Dim ShtArray1(3,50) as Variant
  • Dim ShtArray2(3,50) as Variant
  • ShtArray1 = Range(“a1:c50”).Value
  • ShtArray2 = Range(“d1:f50”).Value

Use:

  • Dim SheetArray(2,3,50) as Variant
  • SheetArray(1) = Range(“a1:c50”).Value
  • SheetArray(2) = Range(“d1:f50”).Value

<Mod's note - Changed the title for better clarity >

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

15 answers

Sort by: Most helpful
  1. Anonymous
    2016-01-11T20:04:48+00:00

    If you look closely, you will see that ShtArray has been dimensioned as a 2-dimensional array of 1000x20 to contain the worksheet...

         Option  Base 1

         Dim ShtArray(1000,20) as Variant

                              .

                              .

         ShtArray = Range("A1:T1000")

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Anonymous
    2016-01-11T16:42:41+00:00

    Thank you for your response. That is what I did to move the two worksheets. However, I was looking for a way to move an entire worksheet into the 3-dimensional array with a single statement by only specifying the 1st dimension (worksheet number) similar to how I moved the entire worksheet into the 2-dimensional array with a single statement:

         ShtArray = Range("A1:T1000")      - see above

    Is this possible?

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. Anonymous
    2016-01-11T01:55:55+00:00

    I am able to copy an entire worksheet of 20 columns x 1000 rows to a 2-dimensional array with a single statement as shown below...

    Option Base 1

    Dim ShtArray(1000,20)

              .

              .

              .

    ShtArray = Range("A1:T1000")

    Is it possible to copy the same worksheet to a 3-dimensional array with a single statement in a similar way where the 1st dimension is the worksheet number and the 2nd and 3rd dimensions are the row and column values as above? I want to be able to copy 2 worksheets to the array without have to copy each worksheet column-by-column and row-by-row...

    Option Base 1

    Dim ShtArray(2,1000,20)

    .

    .

    .

    ShtArray(1,?,?) = Sheets("Sheet1").Range("A1:T1000")

    ShtArray(2,?,?) = Sheets("Sheet2").Range("A1:T1000")

    I still do NOT understand how to move a 2 2-dimensional arrays to a single 3-dimensional array...          

    Was this answer helpful?

    0 comments No comments