Consulting

Results 1 to 3 of 3

Thread: Advanced Filter Help

  1. #1
    VBAX Newbie
    Joined
    Dec 2017
    Posts
    1
    Location

    Advanced Filter Help

    Group,

    I also have a Adv filter issue that I can't seem to resolve. Everything works except when nothing is returned. Any suggestions on how to contain this?

    Private Sub cmdSearch_Click()
    
    
        Dim txtSearchCrit As String
        Dim FindMe As Range
        Dim DataSH As Worksheet
        
        
        
        'set object variables
        Set DataSH = Sheet5
        DataSH.Range("A1").Select
        
        Application.ScreenUpdating = False
        
        If cmbSearchBy = "" Then
        
            MsgBox "Please enter in a Search By Category"
            Exit Sub
            
        End If
            
        If Me.cmbSearchBy = "PartNumber" Then
        
                DataSH.Range("H3") = "*" & Me.txtSearchCrit.Value & "*"
                Set FindMe = txtSearchCrit
        Else
                DataSH.Range("I3") = "*" & Me.txtSearchCrit.Value & "*"
            
        End If
            
                   
                 
            Application.CutCopyMode = False
            
            Range("Parts_List[#All]") _
            .AdvancedFilter _
             Action:=xlFilterCopy, _
             CriteriaRange _
             :=DataSH.Range("H2:I3"), _
             CopyToRange:=DataSH.Range("K2:M2"), _
             Unique:=False
        
                
        'Add the search results to the list box
        If Not DataSH.Range("SearchResult") Is Nothing Then
            
            lstPartsSearch.RowSource = DataSH.Range("SearchResult").Address
            
        Else
            MsgBox "Your part was not found"
        End If
        
        'Clear the values in the search criteria cells
        Sheet5.Range("H3:I3").Value = ""
        
        Application.ScreenUpdating = True
        
    End Sub
    Last edited by Jacob Hilderbrand; 12-12-2017 at 10:50 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Moderator Bump
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Could you be more specific as to what the actual problem is?
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •