VBA to Transfer Data from Worksheet to Worksheet and Skip Row

tsroque

Board Regular
Joined
Jan 19, 2007
Messages
127
Office Version
  1. 365
I have a data table of almost 7000 products. I only need 3 of the columns for my final report (J, K, and O...Part Number, Description and Price). What is a quick and easy way to transfer defined columns to another worksheet (starting row 7, in columns A, C and E) and have a blank row between each row?

Thank you!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
try:
Code:
Sub CopyPasteInsertRowEveryOther()
    Dim arrCol As Variant, i As Integer
    Dim LastRow As Long, LastMax As Long
    Dim shSource As Worksheet, shDestin As Worksheet
    
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    
    Set shDestin = Sheets("Sheet1")
    Set shSource = Sheets("Sheet2")
    arrCol = Array("J", "A", "K", "C", "O", "E")
    
    For i = 0 To 5 Step 2
        LastRow = shSource.Range(arrCol(i) & Rows.Count).End(xlUp).Row
        If LastMax < LastRow Then LastMax = LastRow
        shSource.Range(arrCol(i) & "1:" & arrCol(i) & LastRow).Copy shDestin.Range(arrCol(i + 1) & "7")
    Next i
    For i = LastMax + 7 To 8 Step -1
        Range("A" & i & ",C" & i & ",E" & i).Insert Shift:=xlDown
    Next i
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
End Sub
 
Upvote 0
Hi Warship!

I forgot to mention that source sheet starts on row 3. Also, it works but it's copying as a formula instead of text. The values in J and K are text and O is currency. All three contain values are based off a formula in the source sheet. Other than that, it works...LOL! If I can get the #Ref error fixed, I will be interesting to see how it handles 7000 lines ;)
 
Upvote 0
Please update me on the 7000 run.

get the #Ref error fixed
error ???

Code:
Sub CopyPasteInsertRowEveryOther2()
    Dim arrCol As Variant, i As Integer
    Dim LastRow As Long, LastMax As Long
    Dim shSource As Worksheet, shDestin As Worksheet
    
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    
    Set shDestin = Sheets("Sheet1")
    Set shSource = Sheets("Sheet2")
    arrCol = Array("J", "A", "K", "C", "O", "E")
    
    For i = 0 To 5 Step 2
        LastRow = shSource.Range(arrCol(i) & Rows.Count).End(xlUp).Row
        If LastMax < LastRow Then LastMax = LastRow
        shSource.Range(arrCol(i) & "3:" & arrCol(i) & LastRow).Copy
        shDestin.Range(arrCol(i + 1) & "7").PasteSpecial xlPasteValues
    Next i
    For i = LastMax + 7 To 8 Step -1
        Range("A" & i & ",C" & i & ",E" & i).Insert Shift:=xlDown
    Next i
    
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
End Sub
 
Last edited:
Upvote 0
Works like a charm! But apparently not for 7000 source lines...LOL!!!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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