Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The following is more general than my previous posting; it assumes your
data is in columns a:c, indefinite number of rows up to 20,000 (which is arbitrary--it can be increased as needed): Sub testIt1() Dim rng As Range, i As Long, j As Long Set rng = Sheets("Sheet4").Range("a2: c2").Rows j = 1 For i = 1 To 20000 Step 25 If Application.CountA(rng(i & ":" & i + 24).Cells) 0 Then Worksheets.Add ActiveSheet.Name = "Report" & j rng.Rows(i & ":" & i + 24).Copy ActiveSheet.Range("A2") j = j + 1 Else Exit Sub End If Next End Sub Alan Beban Alan Beban wrote: 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
LOOPING STRUCTURE DESIRED 4 TWO RANGES | Excel Discussion (Misc queries) | |||
LOOPING multiple ranges | Excel Discussion (Misc queries) | |||
looping through rows and columns | Excel Discussion (Misc queries) | |||
Looping in VB with cell ranges | Excel Worksheet Functions | |||
Looping a selection of rows | Excel Discussion (Misc queries) |