• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code autofilter

Hello Experts.

Learnt lot of things from this forum.
Started writing code now a days but struck with some thing called auto filter.

When we do auto filter and no data found..how to stop shooting error.

Cheers!
 
Hi !

Without a crystal clear explanation neither your code …

Just activate Macro recorder and operate manually :
you will get your own code base !
 
Hello Marc.

Here is my macro which work great..but what if the value india not available in the autofilter?

Code:
Sub Macro1()

    Range("C3").Select
    Selection.AutoFilter
    ActiveSheet.Range("$C$3:$C$7").AutoFilter Field:=1, Criteria1:="=India", _
        Operator:=xlAnd
End Sub
 
Last edited by a moderator:
Hello James.

Test it..

Code:
Sub test()
Dim r As Range, j As Integer
Set r = Range(Range("A1"), Range("A1").End(xlDown))
r.AutoFilter field:=1, Criteria1:="India"
j = WorksheetFunction.Count(r.Cells.SpecialCells(xlCellTypeVisible))
'MsgBox j
If j = 0 Then
MsgBox "there is not filtered data"
End If
ActiveSheet.AutoFilterMode = False
End Sub
 
Back
Top