Looping through Ranges of Rows
The following assumes your 91 rows of data is in A2:C92 of a sheet named
"data"; it copies the data to a range with the upper left cell of A2 to
allow room on each Report sheet of the headings in row 1:
Sub testIt1()
Dim rng As Range, i As Long, j As Long
Set rng = Sheets("data").Range("a2: c92").Rows
If rng.Count Mod 25 = 0 Then
n = rng.Count \ 25
Else
n = rng.Count \ 25 + 1
End If
j = 1
For i = 1 To 25 * n Step 25
Worksheets.Add
ActiveSheet.Name = "Report" & j
rng.Rows(i & ":" & i + 24).Copy ActiveSheet.Range("A2")
j = j + 1
Next
End Sub
Alan Beban
MS News wrote:
Here is my case:
I get raw data from offices, which I have to simply separate by
25 rows and make separate "nice" reports, for instance:
ID___NAME______AMOUNT
01---MIKE------$6600
XX---XXXX------$XXXX
91---JANET-----$4500
In the example above I have 91 rows of raw data.
If i did this manually I would have to make 4 reports out of
this, because every nice report that I make is supposed to have
25 records.
So how do I make a loop that will check every 25 row range for
data, and if data was found then copy all 25 rows and paste it on
a Report1, then check the next range from row 26 to 50. Again if
there's anything then copy and paste it on Report2 sheet, and so
on until the range has no data.
I would love to hear back from you on this matter,
Thanks a bunch,
Nile
|