+ Reply to Thread
Results 1 to 7 of 7

Simple loop & array question.

  1. #1
    Registered User
    Join Date
    12-24-2014
    Location
    Budapest, Hungary
    MS-Off Ver
    2013
    Posts
    7

    Simple loop & array question.

    So, all I want to do is a Do Until the end of an array loop. Here's my current code:

    Please Login or Register  to view this content.
    I get the subscript out of range error.
    Last edited by randomdude; 01-17-2015 at 05:39 PM.

  2. #2
    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
    44,463

    Re: Simple loop & array question.

    What are you trying to do?

    Suggest you post a sample workbook and describe the process. Might be other options.

    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


  3. #3
    Registered User
    Join Date
    12-24-2014
    Location
    Budapest, Hungary
    MS-Off Ver
    2013
    Posts
    7

    Re: Simple loop & array question.

    Alright, there are some teams in the 6th column, starting from the 8th row, and I want to add each one to the allTeams array, but only if the team isn't already in the array, therefore the same team won't be added 2 or more times into the allTeams array.

    Here's more of the code (changed i-7 to j to keep it more easy to read):

    Please Login or Register  to view this content.

  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
    44,463

    Re: Simple loop & array question.

    Three options:

    1. A Collection
    2. Create a Dictionary
    3. Use an Advanced Filter to extract the unique entries and sort them, then drop the sorted range into an array.


    Regards, TMS

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Simple loop & array question.

    As TMS suggests.. try a Dictionary..

    It puts all the values in your 6th column into a Dictionary and then assigns the Uniques values (Keys) to the allTeams array.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-24-2014
    Location
    Budapest, Hungary
    MS-Off Ver
    2013
    Posts
    7

    Re: Simple loop & array question.

    Thank you, both of you, it works now.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Simple loop & array question.

    You declared allTeams as a dynamic array:
    Dim allTeams() As String

    It has no no elements at this point so
    Do Until allTeams(j) <> ""

    throws an error.

    Since j = 1 at this point,
    ReDim Preserve allTeams(j)

    will dimension the array with TWO elements, 0 & 1
    Ben Van Johnson

+ 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. Simple loop question
    By kwagam in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-24-2014, 06:20 AM
  2. [SOLVED] Simple For loop Question
    By Boo123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2014, 05:17 PM
  3. [SOLVED] Loop & Array (Probably Simple!)
    By B_B in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 10:50 PM
  4. simple loop question
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2005, 04:05 PM
  5. Simple question on For...Next loop
    By Alex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-26-2005, 11:05 AM

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