Copy/Paste rows if contains specific text, in a list

hs126

New Member
Joined
Apr 25, 2018
Messages
2
Hi all

I'm stuck on this problem and hoping someone can help.

I have a list of data- (up to 1000 rows)
I want to find text “Address” and each time it’s found, copy and paste 4 rows (address and the 3 rows below). It would be great if these could be pasted under the cell containing the word “Name”.

i.e.
Before
A
Name
B
C
AddressY
Y
Y
Y

<tbody>
</tbody>


After
A
Name
AddressY
Y
Y
Y
B
C

<tbody>
</tbody>


If anyone can help that would be amazing, Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi & welcome to MrExcel.
How about
Code:
Sub CutMoveUp()
   Dim Addar As Areas
   Dim Namear As Areas
   Dim i As Long
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Replace "Address", "=XXX", xlWhole, , False, , False, False
      Set Addar = .SpecialCells(xlFormulas, xlErrors).Areas
      .Replace "=XXX", "Address", xlWhole, , False, , False, False
      .Replace "Name", "=XXX", xlWhole, , False, , False, False
      Set Namear = .SpecialCells(xlFormulas, xlErrors).Areas
      .Replace "=XXX", "Name", xlWhole, , False, , False, False
   End With
   For i = 1 To Addar.Count
      If Addar(i).Row > Namear(i).Row + 1 Then
         Addar(i).Resize(4).EntireRow.Cut
         Namear(i).Offset(1).EntireRow.Insert
      End If
   Next i
Application.CutCopyMode = False
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

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