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!!
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,028
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
Glad we got it all sorted out.
:)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,147,482
Messages
5,741,402
Members
423,657
Latest member
Medrok2021

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
Top