Help creating macro that if cell contains x copy and paste that row +11 rows prior to new sheet

apesgrapes

New Member
Joined
Jan 13, 2018
Messages
1
I've found several macros and edited several that allow you to copy and paste to separate sheet if a cell contains certain content. However what I need is one that will search column A for a cell containing a string of text, then copy and paste rows containing that text, as well as the 11 rows preceding, to a different sheet.

My experience involves mostly recording macros and editing as needed, but I cannot figure out how to get it to copy additional rows in addition to the row containing the searched text.

Any help is appreciated!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi & welcome to the board
How about
Code:
Sub FindCopy()

   Dim Fnd As Range
   
   With Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
      Set Fnd = .Columns(1).Find("Cat", , , xlPart, , , False, , False)
      If Not Fnd Is Nothing Then
         Fnd.Offset(-11).Resize(12).EntireRow.Copy Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range("A" & Rows.Count).End(xlUp).Offset(1)
      End If
   End With
End Sub
Change sheets names in red to suit
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

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