Paste a set of rows multiple times throughout a sheet

philipg

New Member
Joined
Sep 24, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all, I am looking to copy ten rows from the top of a sheet, and insert those ten rows hundreds of times throughout a sheet.

I have included a couple of images below - the ten rows to be copied are Cost1 to Cost10, and I want to insert these for each asset (Asset1 to Asset500 or so)

Thanks in advance!
 

Attachments

  • Screenshot 2021-09-24 171121.png
    Screenshot 2021-09-24 171121.png
    11.5 KB · Views: 14
  • Screenshot 2021-09-24 171152.png
    Screenshot 2021-09-24 171152.png
    12.7 KB · Views: 15

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this following your data structure posted.
VBA Code:
Sub Asset()

Dim n As Long
Dim noAsset As String
Dim RngFound As Range, rngAsset As Range

Set RngData = Range("A4", "A13")

For n = 1 To 500
    noAsset = "Asset" & n
    Set rngAsset = Range("A15", Cells(Rows.Count, "A"))
    Set RngFound = rngAsset.Find(noAsset)
    If Not RngFound Is Nothing Then
        RngData.Copy
        RngFound.Offset(1).Insert Shift:=xlDown
    End If
Next

End Sub
 
Upvote 0
Thanks Zot - As I wanted to copy entire rows I changed RngData to Rows("4:13"), and amended the Set rngAsset line to start at A14 so the costs were copied to the first and all subsequent assets. I'm totally new to VBA so if any of these changes have issues I'm not aware of please let me know! seems to be working well now though, thanks! Amended code below for 30 assets:

VBA Code:
Sub Asset()

Dim n As Long
Dim noAsset As String
Dim RngFound As Range, rngAsset As Range

Set RngData = Rows("4:13")

For n = 1 To 30
    noAsset = "Asset" & n
    Set rngAsset = Range("A14", Cells(Rows.Count, "A"))
    Set RngFound = rngAsset.Find(noAsset)
    If Not RngFound Is Nothing Then
        RngData.Copy
        RngFound.Offset(1).Insert Shift:=xlDown
    End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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