![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 07:26 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com