Macro to move data based on multiple filters in one column, part 2

akg742

New Member
Joined
Mar 13, 2014
Messages
39
My original question for this project was answered quickly (thanks, iggydarsa!) but I have a follow up:

The suggested code worked perfectly to pull the rows according to my first 3 criteria but, when I added more, it just moved everything to my destination(wsOut) sheet (including my header row). Is there a limit? This is what I have:

m = wbSource.Range("J" & wbSource.Rows.Count).End(xlUp).Row
On Error Resume Next
wbSource.Range("A1:K1").AutoFilter Field:=10, _
Criteria1:="cnv*", Operator:=xlOr, _
Criteria2:="cork*", Operator:=xlOr, _
Criteria3:="(E)*" , Operator:=xlOr, _
Criteria4:="Inst*", Operator:=xlOr, _
Criteria5:="IRL*", Operator:=xlOr, _
Criteria6:="JR-*", Operator:=xlOr, _
Criteria7:="kz*", Operator:=xlOr, _
Criteria8:="nv-*", Operator:=xlOr, _
Criteria9:="mah-*", Operator:=xlOr, _
Criteria10:="(s)*", Operator:=xlOr, _
Criteria11:="saz*", Operator:=xlOr, _
Criteria12:="sgs*", Operator:=xlOr, _
Criteria13:="t&e*", Operator:=xlOr, _
Criteria14:="te-*"
With wbSource.Range("J2:J" & m).SpecialCells(xlCellTypeVisible).EntireRow
.Copy Destination:=wsOut.Range("A" & Rows.Count).End(xlUp).Offset(1)
.Delete
End With
For Each ws In Worksheets ' Clear all filters
If ws.AutoFilterMode = True Then
Debug.Print ws.Name
ws.AutoFilterMode = False
End If
Next
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try This:
VBA Code:
m = wbSource.Range("J" & wbSource.Rows.Count).End(xlUp).Row
On Error Resume Next
wbSource.Range("A1:K1").AutoFilter Field:=10, _
Criteria1:="cnv*", Operator:=xlOr, _
Criteria2:="cork*", Operator:=xlOr, _
Criteria3:="(E)*" , Operator:=xlOr, _
Criteria4:="Inst*", Operator:=xlOr, _
Criteria5:="IRL*", Operator:=xlOr, _
Criteria6:="JR-*", Operator:=xlOr, _
Criteria7:="kz*", Operator:=xlOr, _
Criteria8:="nv-*", Operator:=xlOr, _
Criteria9:="mah-*", Operator:=xlOr, _
Criteria10:="(s)*", Operator:=xlOr, _
Criteria11:="saz*", Operator:=xlOr, _
Criteria12:="sgs*", Operator:=xlOr, _
Criteria13:="t&e*", Operator:=xlOr, _
Criteria14:="te-*"

' copy only visible rows (excluding the header row)
With wbSource.Range("A2:K" & m).SpecialCells(xlCellTypeVisible).EntireRow
    .Copy Destination:=wsOut.Range("A" & Rows.Count).End(xlUp).Offset(1)
    .Delete
End With

For Each ws In Worksheets ' Clear all filters
    If ws.AutoFilterMode = True Then
        ws.AutoFilterMode = False
    End If
Next
 
Upvote 0
Try This:
VBA Code:
m = wbSource.Range("J" & wbSource.Rows.Count).End(xlUp).Row
On Error Resume Next
wbSource.Range("A1:K1").AutoFilter Field:=10, _
Criteria1:="cnv*", Operator:=xlOr, _
Criteria2:="cork*", Operator:=xlOr, _
Criteria3:="(E)*" , Operator:=xlOr, _
Criteria4:="Inst*", Operator:=xlOr, _
Criteria5:="IRL*", Operator:=xlOr, _
Criteria6:="JR-*", Operator:=xlOr, _
Criteria7:="kz*", Operator:=xlOr, _
Criteria8:="nv-*", Operator:=xlOr, _
Criteria9:="mah-*", Operator:=xlOr, _
Criteria10:="(s)*", Operator:=xlOr, _
Criteria11:="saz*", Operator:=xlOr, _
Criteria12:="sgs*", Operator:=xlOr, _
Criteria13:="t&e*", Operator:=xlOr, _
Criteria14:="te-*"

' copy only visible rows (excluding the header row)
With wbSource.Range("A2:K" & m).SpecialCells(xlCellTypeVisible).EntireRow
    .Copy Destination:=wsOut.Range("A" & Rows.Count).End(xlUp).Offset(1)
    .Delete
End With

For Each ws In Worksheets ' Clear all filters
    If ws.AutoFilterMode = True Then
        ws.AutoFilterMode = False
    End If
Next
Thanks for your suggestion! Unfortunately, this version leaves the header row but it still moves everything to wsOut, not just what should be filtered.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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