+ Reply to Thread
Results 1 to 5 of 5

Why do columns and rows in the array reverse?

  1. #1
    Registered User
    Join Date
    10-05-2013
    Location
    Moscow, Russia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Why do columns and rows in the array reverse?

    Hi!

    I have a complete reversal of rows and columns in the array, and I can't find a workaround for this.

    I'm trying to fill an array with random values, and when I declare an array like this:

    Dim Arr(1 To 1000, 1 To 6) As Integer

    It is supposed to give me 1000 "rows" and 6 "columns", if I understand everything correctly.

    However the following code completely reverses this: it gives me 6 rows, and 1000 columns and I don't understand why. Please help me correct it.

    Please Login or Register  to view this content.
    Best regards,
    dejavision.
    Last edited by dejavision; 05-19-2014 at 12:48 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why do columns and rows in the array reverse?

    Could it be because you are using Application.Transpose?

    If I remove that I get 1000 rows and 6 columns of random numbers.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-05-2013
    Location
    Moscow, Russia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Why do columns and rows in the array reverse?

    Quote Originally Posted by Norie View Post
    Could it be because you are using Application.Transpose?

    If I remove that I get 1000 rows and 6 columns of random numbers.
    Norie, thank you for your swift reply. Yes, I'm a newbie in VBA and it could be because of Application.Transpose. But then why does Application.Transpose reverse them and how can I apply this function or any other method to get the array to the worksheet? In the final code I'm planning to have 1 million rows and I don't know any method except this to do it fast.

    Best regards,
    dejavision.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why do columns and rows in the array reverse?

    Transposing swaps columns and rows.

    If you miss it out and just use this your code will work just fine and you'lll end up with 6000 random numbers in 6 columns and 1000 rows.
    Please Login or Register  to view this content.
    If you want more random numbers just increase the dimensions of the array and then use something like this to avoid hard-coding the range
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-05-2013
    Location
    Moscow, Russia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Why do columns and rows in the array reverse?

    Quote Originally Posted by Norie View Post
    Transposing swaps columns and rows.

    If you miss it out and just use this your code will work just fine and you'lll end up with 6000 random numbers in 6 columns and 1000 rows.
    Please Login or Register  to view this content.
    If you want more random numbers just increase the dimensions of the array and then use something like this to avoid hard-coding the range
    Please Login or Register  to view this content.

    Thanks a lot, Norie. I've inplemented your advice and now everything works fine.

    Best regards,
    dejavision.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to reverse an array (rows become columns, columns become rows)
    By duby13 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-04-2012, 05:43 PM
  2. [SOLVED] Reverse a spreadsheet reversing columns and rows?
    By Becca in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2006, 03:49 PM
  3. How to reverse order of rows and columns
    By Johnny in forum Excel General
    Replies: 3
    Last Post: 09-11-2005, 11:05 AM
  4. [SOLVED] reverse columns and rows
    By Teri from Florida in forum Excel General
    Replies: 1
    Last Post: 08-12-2005, 12:05 PM
  5. Change data to appear in rows instead of columns (reverse a table.
    By Motheroftwoboys in forum Excel General
    Replies: 2
    Last Post: 03-04-2005, 12:06 PM

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