ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop within a loop (https://www.excelbanter.com/excel-programming/420551-loop-within-loop.html)

Brian

Loop within a loop
 
Can I do a loop within a loop
I want to print scoresheets for squads

In cell "A1" I have the number of squads and in cell "A2" the number
of scoresheets for each squad.

In cell "U3" the macro must insert on the scoresheet a 1 for the squad
number and in "W3" a 1 for the round number
I then want to print 1 scoresheet, then increment "W3" by 1 for round
2, print another sheet and continue to do this until "W3" is equal to
the number of scoresheets in "A2"
It must then insert the next squad number in "U3" and run through the
same loop as above to print the right number of scoresheets for squad
2 and must continue to loop until the squad number ("U3") equals the
value in "A1"

Can you help.

Bob Phillips[_3_]

Loop within a loop
 
Simple enough


For i = 1 To Range("A2").Value

Range("U3").Value = Range("U3").Value + 1
For j = 1 To Range("A1").Value

Range("W3").Value = Range("W3").Value + 1

'rest of your code
Next j
Next i

--
__________________________________
HTH

Bob

"Brian" wrote in message
...
Can I do a loop within a loop
I want to print scoresheets for squads

In cell "A1" I have the number of squads and in cell "A2" the number
of scoresheets for each squad.

In cell "U3" the macro must insert on the scoresheet a 1 for the squad
number and in "W3" a 1 for the round number
I then want to print 1 scoresheet, then increment "W3" by 1 for round
2, print another sheet and continue to do this until "W3" is equal to
the number of scoresheets in "A2"
It must then insert the next squad number in "U3" and run through the
same loop as above to print the right number of scoresheets for squad
2 and must continue to loop until the squad number ("U3") equals the
value in "A1"

Can you help.





All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com