+ Reply to Thread
Results 1 to 8 of 8

Loops and arrays

  1. #1
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Loops and arrays

    I am working on an assignment for class. I am supposed to get 25 random numbers to appear in A1:E5, then using arrays and loops, I am supposed to get the same numbers to appear in cells F1:F25.
    There are 3 parts to this assignment:
    Part 1: fill cells A1:E5 with random integers between 0 - 99
    Part 2: fill the two-dimensional array with the values of cells A1:E5
    Part 3: fill cells F1:F25 from the two-dimensional array.
    Here is my code followed by the issue I am having.

    Please Login or Register  to view this content.
    I keep getting a runtime error 9 and it highlights " intTwoDimArray(intRowIndex - 1, intColumnIndex - 1) = Cells(intRowIndex, Chr(64 + intColumnIndex))."'
    Please help and any and all help is appreciated.
    Last edited by LadyB; 04-12-2013 at 04:09 PM.

  2. #2
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Loops and arrays

    Quote Originally Posted by LadyB View Post
    I am working on an assignment for class. I am supposed to get 25 random numbers to appear in A1:E5, then using arrays and loops, I am supposed to get the same numbers to appear in cells F1:F25.
    There are 3 parts to this assignment:
    Part 1: fill cells A1:E5 with random integers between 0 - 99
    Part 2: fill the two-dimensional array with the values of cells A1:E5
    Part 3: fill cells F1:F25 from the two-dimensional array.
    Here is my code followed by the issue I am having.

    Please Login or Register  to view this content.
    I keep getting a runtime error 9 and it highlights " intTwoDimArray(intRowIndex - 1, intColumnIndex - 1) = Cells(intRowIndex, Chr(64 + intColumnIndex))."'
    Please help and any and all help is appreciated.

    It seems I post on here and go back and try again and I figure it out.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,252

    Re: Loops and arrays

    You loop from 0 to 4 in both your inner and outer loops but you subtract 1 from those indexes so, first time through, you will try to use element -1, -1

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,252

    Re: Loops and arrays

    And your solution?

    Regards, TMS

  5. #5
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Loops and arrays

    Quote Originally Posted by TMShucks View Post
    And your solution?

    Regards, TMS

    I took out the -1 and in turn put put a +1 on intRowIndex and IntcolIndex. Then completely redid my loop for the F column. and now it works.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,252

    Re: Loops and arrays

    It is often the way that, when you explain your problem, you can see the solution for yourself.

    And it's usually the best way

    Regards, TMS



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Loops and arrays

    Thanks for helping.
    Last edited by LadyB; 04-12-2013 at 04:09 PM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,252

    Re: Loops and arrays

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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