Autofilter: 1 Field, Multiple Words - NOTHING WORKS

Tash Point O

New Member
Joined
Feb 12, 2018
Messages
47
Hello All,

I've been racking my brains trying to shorten a recorded autofilter macro. I recorded the macro 3x's because I have 3 words I need it to find, then it clears entire rows when it finds that word.

I want to make it more compact and put all 3 criteria(words) into 1 and not have 3 different subroutines. I've tried it all, including using Operator:= xlAnd, and then trying xlOr. Nothing is working

Note that the recorded macro uses wildcard, not sure why. I don't need that.

2z84zz5.jpg


The words are ACM, EM, PAL

Here is what the Data Set looks like:

2klg8k.jpg
 
How about
Code:
Sub Clear_Methodolody_Lines()
With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = False
    With .Range("A1", .Range("A" & Rows.count).End(xlUp))
        .AutoFilter 1, "*ACM*", xlOr, "*EM*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.ClearContents
        On Error GoTo 0
        .AutoFilter 1, "*PAL*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.ClearContents
        On Error GoTo 0
    End With
    .AutoFilterMode = False
End With

End Sub
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Sorry can you also post the code you used that cleared cells in the other columns when using Total*


Absolutely:

Code:
Sub newway()
With ActiveSheet
With Range("A1", Range("A" & Rows.Count).End(xlUp))
 
        .AutoFilter 1, "<>Total*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.ClearContents
    End With
    .AutoFilterMode = False
End With
End Sub
 
Upvote 0
How about
Code:
Sub Clear_Methodolody_Lines()
With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = False
    With .Range("A1", .Range("A" & Rows.count).End(xlUp))
        .AutoFilter 1, "*ACM*", xlOr, "*EM*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.ClearContents
        On Error GoTo 0
        .AutoFilter 1, "*PAL*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.ClearContents
        On Error GoTo 0
    End With
    .AutoFilterMode = False
End With

End Sub


This worked! I really wonder when I will get good enough to play around with syntax to come up with work arounds, like this. So frustrating. Thank you for cracking the case. =)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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