Copy 3 rows above and insert?

hxrolan091

New Member
Joined
Jul 29, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi

I need help with this macro code. I just want to copy the content of 3 above with the number (91) and insert the copied rows below it and loop it.


excelrowscopyandinsert334.jpg


and secondly. I have thousands of rows (17501). Is there other ways to speed up the copy and insert process?

Here is the marco code. I just can't seem to get the right.

Thanks in advance!!

VBA Code:
Public Sub CopyRows()

Dim Col As Variant
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Col = "D"
StartRow = 2
LastRow = Sheets("Sheet1").Cells(Rows.Count, Col).End(xlUp).Row

Application.ScreenUpdating = False

With Sheets("Sheet1")
    For R = LastRow To StartRow + 1 Step -1
        If .Cells(R, Col) = "91" Then
            'Cells(R + 1, Col).Offset(-3, 0).EntireRow.Copy
            '.Cells(R, Col).EntireRow.Insert Shift:=xlDown
            .Cells(R + 1, Col).EntireRow.Copy
            .Cells(R + 1, Col).EntireRow.Insert Shift:=xlDown
        End If
Next R
End With

Application.CutCopyMode = False
Application.ScreenUpdating = True
    
End Sub


Thanks in advance!!
 
You are welcome.
Glad we got it all sorted out.
:)
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,724
Messages
6,126,485
Members
449,316
Latest member
sravya

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