Autofilter for values that are not equal

cesnaplane

New Member
Joined
Jun 1, 2012
Messages
1
Hi everybody,

I need to delete all the rows where values in column M does not match the criteria (cell from another sheet).

Code:
Sub Deletetherow()
'
With ActiveSheet
    .AutoFilterMode = False
    With Range("M1", Range("M" & Rows.Count).End(xlUp))
        .AutoFilter 1, Criteria1:="<>" & CStr(Sheets("Criteria").Range("$B$6"))
            On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With

End Sub

However this macro does delete all the rows, including ones that matches the criterion. Otherwise, if I use the code .AutoFilter 1,
Code:
Criteria1:=CStr(Sheets("Criteria").Range("$B$6"))
it works properly and detele the rows that matches the criterion.

The rows contain strings with values "57.1" , "57.2", etc. (I use comma for decimical point instead of dot).
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,203,198
Messages
6,054,068
Members
444,700
Latest member
Support required please

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