Find and then copy entire row to new sheet

Can an expert provide me with VBA code that will copy entire row[s] to a new sheet if any of the following is in column I

1-10 Days
10-20 Days
 > 20 Days
 0-1 Days
 2-5 Days
 >5 Days

I need to copy all rows that contain the above into sheet named Mena-Aged
JagwarmanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Sub c2sheets()
astrConditions = "1-10 Days,10-20 Days,> 20 Days,0-1 Days,2-5 Days,>5 Days"

Set SrcSheet = ActiveSheet
Set DestSheet = Sheets("Mena-Aged")
For Idx = 2 To Range("I2:I" & Range("I" & Rows.Count).End(xlUp).Row).Count + 1
    If InStr(1, astrConditions, SrcSheet.Range("I" & Idx).Value, 1) > 0 Then
        SrcSheet.Range(Idx & ":" & Idx).Copy DestSheet.Range("I" & Cells.Rows.Count).End(xlUp).Offset(1).EntireRow
    End If
Next
End Sub

Open in new window

Regards
FarWestCommented:
I think the code above can be problematic,  because if word "Days" is the only word or "0 Days" and maybe other instances will consider match it better to change the flowing


astrConditions = "1-10 Days,10-20 Days,> 20 Days,0-1 Days,2-5 Days,>5 Days"

Open in new window

to

astrConditions = "|1-10 Days|10-20 Days|> 20 Days|0-1 Days|2-5 Days|>5 Days|"

Open in new window


and this line
    If InStr(1, astrConditions, SrcSheet.Range("I" & Idx).Value, 1) > 0 Then

Open in new window


to
    If InStr(1, astrConditions, "|"+SrcSheet.Range("I" & Idx).Value+"|", 1) > 0 Then

Open in new window

JagwarmanAuthor Commented:
Hi Rgonzo,

I am getting Variables not defined, can you help please
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

FarWestCommented:
Remove "option explicit" from top of coding Windows
Rgonzo1971Commented:
Hi,

pls try (Edited code)
Sub c2sheets()
Dim strConditions As String
Dim SrcSheet As Worksheets
Dim DestSheet As Worksheets
Dim Idx As Long

strConditions = "1-10 Days,10-20 Days,> 20 Days,0-1 Days,2-5 Days,>5 Days"

Set SrcSheet = ActiveSheet
Set DestSheet = Sheets("Mena-Aged")
For Idx = 2 To Range("I2:I" & Range("I" & Rows.Count).End(xlUp).Row).Count + 1
    If InStr(1, strConditions, SrcSheet.Range("I" & Idx).Value, 1) > 0 Then
        SrcSheet.Range("A" & Idx).EntireRow.Copy DestSheet.Range("I" & Cells.Rows.Count).End(xlUp).Offset(1).EntireRow
    End If
Next
End Sub

Open in new window

JagwarmanAuthor Commented:
Hi Rgonzo I get Type mismatch at

Set SrcSheet = ActiveSheet
Rgonzo1971Commented:
s too much

now
Sub c2sheets()
Dim strConditions As String
Dim SrcSheet As Worksheet
Dim DestSheet As Worksheet
Dim Idx As Long

strConditions = "1-10 Days,10-20 Days,> 20 Days,0-1 Days,2-5 Days,>5 Days"

Set SrcSheet = ActiveSheet
Set DestSheet = Sheets("Mena-Aged")
For Idx = 2 To Range("I2:I" & Range("I" & Rows.Count).End(xlUp).Row).Count + 1
    If InStr(1, strConditions, SrcSheet.Range("I" & Idx).Value, 1) > 0 Then
        SrcSheet.Range("A" & Idx).EntireRow.Copy DestSheet.Range("I" & Cells.Rows.Count).End(xlUp).Offset(1).EntireRow
    End If
Next
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JagwarmanAuthor Commented:
so simple when you know how... I just wish I did. Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.