Excel VBA to check autofilter for data

Posted by cav719 on Stack Overflow See other posts from Stack Overflow or by cav719
Published on 2012-10-01T21:35:23Z Indexed on 2012/10/01 21:37 UTC
Read the original article Hit count: 282

Filed under:
|
|
|

I need help checking for autofiltered rows not including the header. I want it to give a message box "No records found." then exit sub or continue with copy paste if there are rows beyond the header row. I know I need an If/Else entry after the filter to check for data but I'm having trouble figuring how to check. This code is being done from a UserForm I created.

Here is my script:

Private Sub Searchbycompanyfield_Click()

If CompanyComboBox1.Value = "" Then
    MsgBox "Please enter a Company to begin search."
    Exit Sub
End If
ActiveSheet.Range("$A:$H").AutoFilter Field:=1, Criteria1:=EQDataEntry.CompanyComboBox1.Value, Operator:=xlOr
Cells.Select
Selection.Copy
Sheets("Sheet2").Select
Range("A5").Select
ActiveSheet.Paste
Call MessageBoxYesOrNoMsgBox

End Sub

Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about excel

Related posts about vba