duteberta
Board Regular
- Joined
- Jun 14, 2009
- Messages
- 92
- Office Version
- 365
- Platform
- MacOS
I've been working all day to no avail. Not sure why table is not filtering when activating this macro.
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].
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].