Table filter search box VBA not working...

duteberta

Board Regular
Joined
Jun 14, 2009
Messages
92
Office Version
  1. 365
Platform
  1. MacOS
I've been working all day to no avail. Not sure why table is not filtering when activating this macro.

VBA Code:
Option Explicit

Sub AgentFilter()

    Dim aQuery As String
    Dim LastRow As Long
    
    With sh_AGENTS
        
            LastRow = .Range("C999999999").End(xlUp).Row
            If LastRow < 6 Then LastRow = 6
            
            If .Range("E3") = "Enter search criteria here…" Then aQuery = Empty
            Else: aQuery = .Range("E3").Value
            
            .Range("C7:T" & LastRow).Select
            
            Selection.AutoFilter
                
            With .Range("tbl_AGENTS")
                
                If aQuery <> Empty Then .AutoFilter Field:=2, Criteria:="=*" & Query & "*"
'                If aQuery <> Empty Then .AutoFilter Field:=5, Criteria:="=*" & Query & "*"
'                If aQuery <> Empty Then .AutoFilter Field:=6, Criteria:="=*" & Query & "*"
'                If aQuery <> Empty Then .AutoFilter Field:=7, Criteria:="=*" & Query & "*"

            End With
            
            
    End With

End Sub

Sub ClearAgentFilter()

        With sh_AGENTS
        
'            .Range("A6").Value = True
            
                .AutoFilterMode = False
                .Range("E3").Value = "Enter search criteria here…"
                
'            .Range("A6").Value = False
        
        End With
        
End Sub


My list of agents is very long (about 10,000 agents) I only want to search for matches in columns 2,5,6,7 corresponding to Columns: [MLSID], [Last], [OfficeID], [OfficeName].

Screenshot 2024-04-04 at 1.54.45 PM.png
 
no they do not
In that case, we keep using a cell; however, you can't get a live search as you type. The search will be executed after you leave the cell, i.e., by pressing Enter or Tab.
Let me know if you're interested in this approach.
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In that case, we keep using a cell; however, you can't get a live search as you type. The search will be executed after you leave the cell, i.e., by pressing Enter or Tab.
Let me know if you're interested in this approach.
Yes I'm interested thanks
 
Upvote 0
Could you please upload a sample workbook (without sensitive data) to a file-sharing site like Dropbox.com or Google Drive, and then share the link here?
Also, ensure that the link is accessible to anyone.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

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