How can i copy excell data from a sheet by parts?

zabiullakhan

Active Member
Joined
Aug 30, 2010
Messages
310
I want to copy excell data in parts for example 10 rows at a time.
  • I need to determin the no of rows present in the sheet1
  • Copy 10 rows at a time from sheet1 and past into sheet2 (using a loop)
Note : I cant copy the whole data at once as per the requirment.

Please help.
 
Code:
ElseIf IsEmpty(Cells(i + 1, 1)) Then
            Range(Cells(lRows - lLast, 1), Cells(i, 1)).EntireRow.Copy Destination:=sh.Range("A" & sh.Cells(Rows.Count, 1).End(xlUp).Row).Offset(1, 0)
        End If
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,

Maybe this
(adjust the sheet names on the two first lines of code after the Dims)

Code:
Sub copy10()
    Dim wkOrigin As Worksheet, wkDest As Worksheet
    Dim LR As Long, i As Long, j As Long
 
    Set wkOrigin = Sheets("Sheet1")
    Set wkDest = Sheets("Sheet2")
 
    With wkOrigin
        LR = .Cells(.Rows.Count, "A").End(xlUp).Row
        For i = 1 To LR Step 10
            j = i + 9
            If j > LR Then j = LR
            .Rows(i & ":" & j).Copy wkDest.Rows(i & ":" & j)
        Next i
    End With
End Sub

HTH

M.
 
Last edited:
Upvote 0
Try...
Code:
Sub CopyLoop()
    Dim ChunkSize As Integer
    Dim rwLast_Source As Long
    
    Range("A1").Select
    ChunkSize = 10
    
    rwLast_Source = Range("A" & Rows.Count).End(xlUp).Row
    Do While ActiveCell.Row <= rwLast_Source
        ActiveCell.Resize(ChunkSize, 1).EntireRow.Copy _
            Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        ActiveCell.Offset(ChunkSize, 0).Select
    Loop
End Sub
Denis
 
Upvote 0
Hi SydneyGeek - This is cool it works as i wanted, Thanks. However the copied data gets pasted from the 2nd row and can it be from the 1st row. am trying to edit the code for 1st rows its not working out.

Please let me know if this can be done.

Thanks a lot for all your sullutions. :)
 
Upvote 0
Try this version.
Code:
Sub CopyLoop()
    Dim ChunkSize As Integer
    Dim rwLast_Source As Long
    
    'clear out Sheet2, then copy Row 1 across
    Sheets("Sheet2").Range("A1").CurrentRegion.ClearContents
    Range("A1").EntireRow.Copy _
        Destination:=Sheets("Sheet2").Range("A1")
    
    'now do the rest in groups determined by the ChunkSize
    Range("A2").Select
    ChunkSize = 10
    
    rwLast_Source = Range("A" & Rows.Count).End(xlUp).Row
    Do While ActiveCell.Row <= rwLast_Source
        ActiveCell.Resize(ChunkSize, 1).EntireRow.Copy _
            Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        ActiveCell.Offset(ChunkSize, 0).Select
    Loop
End Sub

Denis
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,226
Members
453,152
Latest member
ChrisMd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top