Errorr with Filter and Delete VBA

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello folks:

I am trying to filter and delete in column O anything that does not equal "W". My code keeps erroing out. I think is on the <> sign.


Sub filterMinorityEE()

'Filter all of the minority employees.

Dim LastRow As Long

sheets("minority").Select
LastRow = Range("O" & Rows.Count).End(xlUp).Row
If WorksheetFunction.CountIf(Range("O5:O" & LastRow), <> "W") Then
Application.ScreenUpdating = False
Range("O4:O" & LastRow).AutoFilter Field:=1, Criteria1:<>"W"
Range("O5:O" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True

End If
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
If WorksheetFunction.CountIf(Range("O5:O" & LastRow), [COLOR=#ff0000]"<>W"[/COLOR]) Then
Range("O4:O" & LastRow).AutoFilter Field:=1, Criteria1:[COLOR=#ff0000]="<>W"
[/COLOR]
 
Upvote 0
You're welcome, good luck.
 
Upvote 0

Forum statistics

Threads
1,203,379
Messages
6,055,094
Members
444,761
Latest member
lneuberger

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