+ Reply to Thread
Results 1 to 3 of 3

Arrays - Rows and Columns

  1. #1
    Forum Contributor kraljb's Avatar
    Join Date
    05-26-2004
    Location
    Illinois
    MS-Off Ver
    2007 (recent change)
    Posts
    256

    Arrays - Rows and Columns

    I have a macro that grabs information from spreadsheet1 and verifies it then puts it in a new format on spreadsheet2.

    Here is the essential problem...

    Sub ArrayTest()
    Dim MyArray(9) as Integer
    Dim MyRange1 as Range
    Dim MyRange2 as Range
    Dim Counter as Integer

    Set MyRange1 = Range("A1:A10")
    Set MyRange2 = Range("B1:K1")

    For Counter = 0 to 9
    MyArray(Counter) = Counter
    Next Counter

    MyRange1 = MyArray
    MyRange2 = MyArray

    End Sub

    The problem is that I need the Array to fill in properly down a column, not across a row.

    A solution that I discovered was to change these two parts...

    Dim MyArray(9, 0) as Integer

    For Counter = 0 to 9
    MyArray(Counter, 0) = Counter
    Next Counter

    Is this the only solution, or is there a better one...

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by kraljb
    I have a macro that grabs information from spreadsheet1 and verifies it then puts it in a new format on spreadsheet2.

    Here is the essential problem...

    Sub ArrayTest()
    Dim MyArray(9) as Integer
    Dim MyRange1 as Range
    Dim MyRange2 as Range
    Dim Counter as Integer

    Set MyRange1 = Range("A1:A10")
    Set MyRange2 = Range("B1:K1")

    For Counter = 0 to 9
    MyArray(Counter) = Counter
    Next Counter

    MyRange1 = MyArray
    MyRange2 = MyArray

    End Sub

    The problem is that I need the Array to fill in properly down a column, not across a row.

    A solution that I discovered was to change these two parts...

    Dim MyArray(9, 0) as Integer

    For Counter = 0 to 9
    MyArray(Counter, 0) = Counter
    Next Counter

    Is this the only solution, or is there a better one...
    As far as I can see, the only one, the last element of the array seems to align itsself across the row, the second last down the column.

    A note is that you can use Option Base 1 to start the array from 1 rather than the default zero, this could help for clarity if you are aligning the array to rows and/or columns.

    ---

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    You can also define array with 2 numbers that are lbound and ubound ,
    for example:

    Dim MyArray(1 To 10, 1 To 1) As Integer

    as in the code below:

    Dim MyRange1 As Range
    Dim MyArray(1 To 10, 1 To 1) As Integer

    Set MyRange1 = Range("A1:A10")

    For Counter = 1 To 10
    MyArray(Counter, 1) = Counter
    Next Counter

    MyRange1 = MyArray

+ 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