+ Reply to Thread
Results 1 to 15 of 15

Can you change the order/pattern that vba uses to loop through a range?

  1. #1
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Can you change the order/pattern that vba uses to loop through a range?

    So if i set a "for each cell in range" loop up with range A1 to ?# the loop checks cells in the order A1,B1,C1..?1,A2,B2,C2...?2...A#,B#,C#...?# is there a way to change the order to A1,A2,A3...A#,B1,B2,B3...B#...?1,?2,?3...?#
    I am trying to get a macro to look for three in a three consecutive values in a row or column without having to write a unique loop for each row or column.
    Last edited by Leon V (AW); 06-07-2013 at 05:16 AM. Reason: remove range size limit

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Can you change the order/pattern that vba uses to loop through a range?

    Consider:

    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Can you change the order/pattern that vba uses to loop through a range?

    Maybe using offsets?

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    that would require a lot of code when the ranges expand to most of the sheet!

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Perhaps something like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    that works for the order thanks didn't think of that for some reason but I am unable to use next col inside of the cl loop.
    E.G.
    Please Login or Register  to view this content.
    obviously my actual if statement will be more complex but I keep getting next without for error.

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

    Re: Can you change the order/pattern that vba uses to loop through a range?

    I think you want:
    Please Login or Register  to view this content.

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

    Re: Can you change the order/pattern that vba uses to loop through a range?

    Why would you want to use Next col in the loop?

    If you only want to loop down to row 6 change the range you are looping through.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    the numbers are just for example Norie in the full code the range is variable also as previously stated the if statement is far more complex than that agian just an example to demonstrate the error I get with my actual code (which is several pages long).

    Kyle can I exit for and skip any code between next cl and next col? maybe like:
    Please Login or Register  to view this content.
    sorry about the range edits I needed to be clear that the numbers were just placeholders.

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

    Re: Can you change the order/pattern that vba uses to loop through a range?

    I realise that, and if that's the case using Exit For is the solution for moving onto the next column.

    What other code do you want to execute, or not execute?

    That could probably be dealt with using an If/Else/End If structure, or something similar.

  11. #11
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    the other code stuff is used to creat a probability graph with the data in the column if no consistent results were found

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

    Re: Can you change the order/pattern that vba uses to loop through a range?

    What criteria do you use to decide if the graph should be created?

  13. #13
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    patterns between the previouse cells and the current cell if particular patterns are found the cells need to be remembered for a later graph if no pattern is found then a graph showing which of the other graph types the data would best fit into.
    eg 0,1,2,3,4,5,6 would be picked up to fit into graph A (patern 0-3-6). 3,3,3,3,3,3,3 would be seen to fit into graph B (pattern 3-3-3). however 0,1,2,4,4,5,6 would not fit pattern 0-3-6 perfectly but would fit into graph A better than B, inversly 3,3,3,4,4,3,3 would fit graph B better but doesn't quite follow the pattern.

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

    Could you post a workbook with some sample data/charts?

  15. #15
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: Can you change the order/pattern that vba uses to loop through a range?

    Norie

    Sorry it is proprietary test results and that part of the macro works anyway I just need to be able to skip the pattern not found graph when a pattern is found (i have working equations to determin this) so exiting the cl for
    Last edited by Leon V (AW); 06-14-2013 at 04:42 AM.

+ 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