ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Looping a selection of rows (https://www.excelbanter.com/excel-discussion-misc-queries/60544-looping-selection-rows.html)

Andre Kruger

Looping a selection of rows
 

Hi

I need to create a loop which will select 4 rows copy and paste it to a new
sheet. then go to the Next 4 rows and copy them to a new sheet. I need this
to happen untill the row is blank (empty).

Any idea how to do this loop?



Dave Peterson

Looping a selection of rows
 
I used column A to find that last used row.

Option Explicit
Sub testme()

Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim myStep As Long

Set CurWks = Worksheets("sheet1")

myStep = 4

With CurWks

FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow Step myStep
Set NewWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )
.Rows(iRow).Resize(myStep).Copy _
Destination:=NewWks.Range("a1")
Next iRow

End With

End Sub

Andre Kruger wrote:

Hi

I need to create a loop which will select 4 rows copy and paste it to a new
sheet. then go to the Next 4 rows and copy them to a new sheet. I need this
to happen untill the row is blank (empty).

Any idea how to do this loop?


--

Dave Peterson


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

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