Split and copy data from one sheet to another

sofas

Active Member
Joined
Sep 11, 2022
Messages
478
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have a datasheet consisting of hundreds of rows. I want to copy it to another sheet, adding 4 empty rows between every 10 rows.
For example, data from A3 to Q10000
A1 to Q2 headings
It is required to copy the first and second rows directly at the top of every 10 rows
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi sofas,

It's not super fast (~ 90 seconds for 10,000 records) but this will do the job:

VBA Code:
Option Explicit
Sub Macro1()

    Dim i As Long, j As Long, k As Long, x As Long
    Dim lngStep As Long
    Dim wsSrc As Worksheet, wsDestin As Worksheet
    Dim xlnCalcMethod As XlCalculation
    
    With Application
        xlnCalcMethod = .Calculation
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set wsSrc = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing the raw data. Change to suit if necessary.
    Set wsDestin = ThisWorkbook.Sheets("Sheet2") '<-Sheet name containing the raw data. Change to suit if necessary.
    
    j = 3
    k = wsSrc.Range("A:Q").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lngStep = 10
    
    For i = j To k Step lngStep
        If i = j Then
            wsSrc.Range("A1:Q2").Copy Destination:=wsDestin.Range("A1")
            wsSrc.Range("A" & i & ":Q" & i + lngStep - 1).Copy Destination:=wsDestin.Range("A" & j)
        Else
            x = wsDestin.Range("A:Q").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 5
            wsSrc.Range("A1:Q2").Copy Destination:=wsDestin.Range("A" & x)
            wsSrc.Range("A" & i & ":Q" & i + lngStep - 1).Copy Destination:=wsDestin.Range("A" & x + 2)
        End If
    Next i
    
    With Application
        .Calculation = xlnCalcMethod
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub

Regards,

Robert
 
Upvote 0
Solution

Forum statistics

Threads
1,215,326
Messages
6,124,258
Members
449,149
Latest member
mwdbActuary

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