Thread: COUNTIF VBA
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default COUNTIF VBA

Hi,

Am Fri, 4 Mar 2016 06:23:32 -0800 (PST) schrieb Merritt Ave:

If I use your suggested method, it will give a VBA error when there is NOT an instance of the criteria search - NO CELLS WERE FOUND.


for me it works fine. Do you have headers?

Try:

Dim myCrit As String
myCrit = "MISC"

If Application.CountIf(Range("N1:N1000"), myCrit) 0 Then
Worksheets("Check").Range("N1").AutoFilter Field:=1,
Criteria1:=myCrit
Application.DisplayAlerts = False

ActiveSheet.Range("N2:N1000").SpecialCells(xlCellT ypeVisible).EntireRow.Delete
Application.DisplayAlerts = True
ActiveSheet.AutoFilterMode = False
End If

or:

Const myCrit = "MISC"

If Application.CountIf(Range("N1:N1000"), myCrit) 0 Then
Worksheets("Check").Range("N1").AutoFilter Field:=1,
Criteria1:=myCrit
Application.DisplayAlerts = False

ActiveSheet.Range("N2:N1000").SpecialCells(xlCellT ypeVisible).EntireRow.Delete
Application.DisplayAlerts = True
ActiveSheet.AutoFilterMode = False
End If


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional