I've been using AdvancedFilter to look through a worksheet, then copy and paste rows that meet criteria into another worksheet. (AdvancedFilter successfully works as it should).
I'm now wondering if it's possible to copy additional rows during each AdvancedFilter positive identification.
For example, every time AdvancedFilter finds a value that meets the pre-defined criteria, can it copy the 12 rows below that row and bring those with it to the other worksheet?
Here's my successful AdvancedFilter code:
Sheet4.Range("A1:X10000").AdvancedFilter , CriteriaRange:=Sheet5.Range("B4:B5"), CopyToRange:=Sheet5.Range("A10:X10"), Unique:=False
An alternative might be to use a for and if loop, which I've tried, but I keep getting a 1004 error or 9 error.
any suggestions?
Here's my loop code:
Sheet4.Select
Dim r As Long, endRow As Long, PasteRowIndex As Long
endRow = 100
PasteRowIndex = 11
For r = 2 To endRow
If Cells(r, Columns("A").Column).Value = "Test" Then
Rows(r).Select
Selection.Copy
Sheets("CompanyFilter").Select
Rows(PasteRowIndex).Select
ActiveSheet.Paste
PasteRowIndex = PasteRowIndex + 1
Sheet4.Select
End If
Next r