+ Reply to Thread
Results 1 to 3 of 3

Final Value, For / Next Loop

  1. #1
    Neal Zimm
    Guest

    Final Value, For / Next Loop

    Nothing is mentioned in the remarks for the For / Next Loop about NOT
    being able to change the final value of the counter.

    In my application I have a set number of rows per "page" in a manual, and I
    want to skip the first row of each page.

    I have proven that the following code does NOT work when crossing
    this "first" row boundary. I've coded a work around using do until ....
    by maybe I'm doing something wrong. Any comments?

    For XX = TargetRow To FRow
    If XX Mod RteRowsPPg <> 1 Then Cells(XX, RigCol).Interior.ColorIndex =
    Salmon Else FRow = FRow + 1
    Next XX ' note Salmon is set to a number via a Const statement.

    Thanks,
    Neal Z.



    --
    Neal Z

  2. #2
    K Dales
    Guest

    RE: Final Value, For / Next Loop

    What I think I would do would be to use two loops: one to loop through the
    "pages" and the other to loop through the rows:
    ' I would have code here to calculate PageCount, the number of pages; I assume
    ' you already know the RowsPerPage
    For i = 1 to PageCount
    For j = 2 to RowsPerPage ' skips the first row on the "page"
    'Note how I use i and j to calculate the current row:
    Cells(((i - 1) * RowsPerPage) + j, RigCol).Interior.ColorIndex - Salmon
    Next j
    Next i

    --
    - K Dales


    "Neal Zimm" wrote:

    > Nothing is mentioned in the remarks for the For / Next Loop about NOT
    > being able to change the final value of the counter.
    >
    > In my application I have a set number of rows per "page" in a manual, and I
    > want to skip the first row of each page.
    >
    > I have proven that the following code does NOT work when crossing
    > this "first" row boundary. I've coded a work around using do until ....
    > by maybe I'm doing something wrong. Any comments?
    >
    > For XX = TargetRow To FRow
    > If XX Mod RteRowsPPg <> 1 Then Cells(XX, RigCol).Interior.ColorIndex =
    > Salmon Else FRow = FRow + 1
    > Next XX ' note Salmon is set to a number via a Const statement.
    >
    > Thanks,
    > Neal Z.
    >
    >
    >
    > --
    > Neal Z


  3. #3
    Neal Zimm
    Guest

    RE: Final Value, For / Next Loop

    Thanks KD,
    I'll use your method in other areas of the macro where all or many pages
    have to processed.
    My example is for a specific need, where by your answer I think you
    confirmed the question about NOT being to modify the value of the 'to'
    variable in the for statement while the loop is executing.
    --
    Neal Z


    "Neal Zimm" wrote:

    > Nothing is mentioned in the remarks for the For / Next Loop about NOT
    > being able to change the final value of the counter.
    >
    > In my application I have a set number of rows per "page" in a manual, and I
    > want to skip the first row of each page.
    >
    > I have proven that the following code does NOT work when crossing
    > this "first" row boundary. I've coded a work around using do until ....
    > by maybe I'm doing something wrong. Any comments?
    >
    > For XX = TargetRow To FRow
    > If XX Mod RteRowsPPg <> 1 Then Cells(XX, RigCol).Interior.ColorIndex =
    > Salmon Else FRow = FRow + 1
    > Next XX ' note Salmon is set to a number via a Const statement.
    >
    > Thanks,
    > Neal Z.
    >
    >
    >
    > --
    > Neal Z


+ 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