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
[TABLE="width: 100"]
<tbody>[TR]
[TD]A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Address[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
</tbody>[/TABLE]


After
[TABLE="width: 100"]
<tbody>[TR]
[TD]A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Address[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


If anyone can help that would be amazing, Thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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