LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Looping through Ranges of Rows

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LOOPING STRUCTURE DESIRED 4 TWO RANGES FARAZ QURESHI Excel Discussion (Misc queries) 2 June 5th 09 05:24 PM
LOOPING multiple ranges Jase Excel Discussion (Misc queries) 1 April 7th 08 06:21 PM
looping through rows and columns mattguerilla Excel Discussion (Misc queries) 1 March 20th 07 05:14 PM
Looping in VB with cell ranges Freeman Excel Worksheet Functions 2 January 22nd 06 12:14 PM
Looping a selection of rows Andre Kruger Excel Discussion (Misc queries) 1 December 15th 05 04:18 PM


All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"