+ Reply to Thread
Results 1 to 3 of 3

[SOLVED] Help with multple For/Nexts please

  1. #1

    [SOLVED] Help with multple For/Nexts please

    Hello I dont understand for next, im trying to work with a series of
    variable all of which increment by a certain number every interation.

    what im trying to do
    ----------------------------
    make a string consisting of the the contents of the 6th, 7th, 9th,
    35th, 37th, 38th, 40th, 41st and 42nd columns or multiples of these
    columns. Repeat this extraction until the end of the row is reached.

    This is my code that doesn't work - can someone offer a fixed version
    please.

    ======

    Dim concat As String

    For i = 6 To 6000 Step 6
    For j = 7 To 6000 Step 7
    For k = 9 To 6000 Step 9
    For l = 35 To 6000 Step 35
    For m = 37 To 6000 Step 37
    For n = 38 To 6000 Step 38
    For o = 40 To 6000 Step 40
    For p = 41 To 6000 Step 41
    For q = 42 To 6000 Step 42

    concat = concat & Cells(2, i) & " " & Cells(2, j) & " " & Cells(2,
    k) & " " & Cells(2, l) & " " & Cells(2, m) & " " _
    & Cells(2, n) & " " & Cells(2, o) & " " & Cells(2, p) & " " &
    Cells(2, q)


    Next i
    Next j
    Next k
    Next l
    Next m
    Next n
    Next o
    Next p
    Next q

    ActiveCell = makes

    End Sub
    =====================

    T I A,
    Gary.


  2. #2
    Les
    Guest

    RE: Help with multple For/Nexts please

    The root of your problem is the For....Next structure. You need to reverse
    the order of the 'Next. statements.

    i.e.
    For i = 6 To 6000 Step 6
    For j = 7 To 6000 Step 7
    For k = 9 To 6000 Step 9
    For l = 35 To 6000 Step 35
    For m = 37 To 6000 Step 37
    For n = 38 To 6000 Step 38
    For o = 40 To 6000 Step 40
    For p = 41 To 6000 Step 41
    For q = 42 To 6000 Step 42

    concat = concat & Cells(2, i) & " " & Cells(2, j) & " " _
    & Cells(2, k) & " " & Cells(2, l) & " " & Cells(2, m) & " " _
    & Cells(2, n) & " " & Cells(2, o) & " " & Cells(2, p) _
    & " " & Cells(2, q)

    Next q
    Next p
    Next o
    Next n
    Next m
    Next l
    Next k
    Next j
    Next i

    However, I am sure sure just what you want to accomplish here. An Excel
    workbook does not have 6000 columns available, less than 300 actually.Also,
    your string "concat" is going to grow very large.

    Can you be more precise as to what you want to do?

    --
    Les Torchia-Wells


    "[email protected]" wrote:

    > Hello I dont understand for next, im trying to work with a series of
    > variable all of which increment by a certain number every interation.
    >
    > what im trying to do
    > ----------------------------
    > make a string consisting of the the contents of the 6th, 7th, 9th,
    > 35th, 37th, 38th, 40th, 41st and 42nd columns or multiples of these
    > columns. Repeat this extraction until the end of the row is reached.
    >
    > This is my code that doesn't work - can someone offer a fixed version
    > please.
    >
    > ======
    >
    > Dim concat As String
    >
    > For i = 6 To 6000 Step 6
    > For j = 7 To 6000 Step 7
    > For k = 9 To 6000 Step 9
    > For l = 35 To 6000 Step 35
    > For m = 37 To 6000 Step 37
    > For n = 38 To 6000 Step 38
    > For o = 40 To 6000 Step 40
    > For p = 41 To 6000 Step 41
    > For q = 42 To 6000 Step 42
    >
    > concat = concat & Cells(2, i) & " " & Cells(2, j) & " " & Cells(2,
    > k) & " " & Cells(2, l) & " " & Cells(2, m) & " " _
    > & Cells(2, n) & " " & Cells(2, o) & " " & Cells(2, p) & " " &
    > Cells(2, q)
    >
    >
    > Next i
    > Next j
    > Next k
    > Next l
    > Next m
    > Next n
    > Next o
    > Next p
    > Next q
    >
    > ActiveCell = makes
    >
    > End Sub
    > =====================
    >
    > T I A,
    > Gary.
    >
    >


  3. #3
    João Araújo
    Guest

    Re: Help with multple For/Nexts please

    Hello Gary!
    The is that the Next instruction must be first for the inner nested next.
    So the order should be
    Next q
    Next p
    Next n
    Next m
    and so on.
    HTH
    Joćo Araśjo

    <[email protected]> wrote in message
    news:[email protected]...
    > Hello I dont understand for next, im trying to work with a series of
    > variable all of which increment by a certain number every interation.
    >
    > what im trying to do
    > ----------------------------
    > make a string consisting of the the contents of the 6th, 7th, 9th,
    > 35th, 37th, 38th, 40th, 41st and 42nd columns or multiples of these
    > columns. Repeat this extraction until the end of the row is reached.
    >
    > This is my code that doesn't work - can someone offer a fixed version
    > please.
    >
    > ======
    >
    > Dim concat As String
    >
    > For i = 6 To 6000 Step 6
    > For j = 7 To 6000 Step 7
    > For k = 9 To 6000 Step 9
    > For l = 35 To 6000 Step 35
    > For m = 37 To 6000 Step 37
    > For n = 38 To 6000 Step 38
    > For o = 40 To 6000 Step 40
    > For p = 41 To 6000 Step 41
    > For q = 42 To 6000 Step 42
    >
    > concat = concat & Cells(2, i) & " " & Cells(2, j) & " " & Cells(2,
    > k) & " " & Cells(2, l) & " " & Cells(2, m) & " " _
    > & Cells(2, n) & " " & Cells(2, o) & " " & Cells(2, p) & " " &
    > Cells(2, q)
    >
    >
    > Next i
    > Next j
    > Next k
    > Next l
    > Next m
    > Next n
    > Next o
    > Next p
    > Next q
    >
    > ActiveCell = makes
    >
    > End Sub
    > =====================
    >
    > T I A,
    > Gary.
    >




+ 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