+ Reply to Thread
Results 1 to 13 of 13

array loop that loops through another array

  1. #1
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    array loop that loops through another array

    Good Evening,

    Can someone help me out with this one? I am trying to look for matching values from column A within column B, and if a match is found; then to bring the value of Column B + 1 column over to Column A + 1 column. The way I am trying to do this is with two arrays, where each array is representative of column A and column B. Below is what I have.


    Please Login or Register  to view this content.
    I'm getting an error '9', Subscript out of range error

    If anyone can help me out on this, I'll greatly appreciate it. This forum has really assisted me with getting my feet wet with VBA.

    Thanks,
    Bob

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: array loop that loops through another array

    That error usually means an object you've named can't be found. Perhaps instead of referencing Sheet1 you need to reference Sheets("Sheet1")?

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: array loop that loops through another array

    That didn't have any affect, the error is occuring at:

    Please Login or Register  to view this content.
    I also changed the for loop to:

    Please Login or Register  to view this content.
    What I wanted to do is to use the For loop to loop through the array ranks with the variables i & h. But then, something is not translating over from the array to the i & h array bounds for that particular iteration in the loop. I'm going to try to use the "For Each" loop, but am still unsure how to pull the value out; let alone use the offset method to carry the value of the matching adjacent cell over to the other column.

    Through researching this issue, I found another person with a similar problem; and one person responded by suggesting to use the .Find method. I'm going to look into that.

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: array loop that loops through another array

    can you upload a copy of your workbook, it might be easier to help find a solution.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: array loop that loops through another array

    Range arrays are 2 dimensional, you either need to transpose or loop through the specific dimension

    Please Login or Register  to view this content.

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

    Re: array loop that loops through another array

    j and m are 2 dimensional loops.

    Here you are trying to refer to items in them using only one index.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: array loop that loops through another array

    Sure, here it is.
    Attached Files Attached Files

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: array loop that loops through another array

    Is there an echo in here?

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

    Re: array loop that loops through another array

    As welll as being 2 dimensional the arrays have 1- based indices.

    For example j is 1 to 10, 1 to 1 and m is 1 to 6, 1 to 1.

    This will compile and run.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: array loop that loops through another array

    Hi Norie,

    After reading the response about the dimension of the array, I tried this, lol:

    Please Login or Register  to view this content.
    I'll go ahead and run yours. be right back.

  11. #11
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: array loop that loops through another array

    Hey Everyone,

    Thanks for all of the help. I changed the column references in the Cells object one more column over, cause that was my fault from the beginning.

    I think the difference between my last attempt and Norie's suggestion is that I was trying to loop through the array by defining the dimension as the variable. But, Nories is doing the samething and taking into account the pointer variable, and using the 1 in,


    Please Login or Register  to view this content.
    to point to the rank...or something like that. Big ups to all.
    Ah crap, also; I tried to give "Reputation" to everyone involved, but the site won't let me. Sorry.

    Thanks,
    Bob

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: array loop that loops through another array

    See if this is what you what. Im guessing that you want to add the letter value for the number in column N

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    09-13-2011
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    111

    Re: array loop that loops through another array

    Hi Mike,

    Thanks for the assist. It looks like you're using a lot of methods that I'm not used to using. I'll also look into using your method.

    Thanks all for the help.

    bob1980

+ 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