Classes are a tool in object-oriented programming that make programming much simpler. One class that I have developed in VBA is a class that makes using the AdvancedFilter method extremely easy and useful. In fact, I like it so much that I stopped using the regular find method. In the coming weeks I will demonstrate how this was done.
This is how the AdvancedFilter method works:
Sub AdvancedFilterClassExample()
Dim iIndex As Integer
Dim rResult As Range
Dim clsSearch As Search
'clsSearch.ColumnUnique = 1
'clsSearch.CopyUniqueTo = Range("A101")
clsSearch.IncludeHeaderInResults = True
clsSearch.RangeToFilter = Range("A1:Y100")
clsSearch.FilterLocation = Range("Z1")
iIndex = clsSearch.Add("George")
clsSearch(iIndex).Header = "First Name"
clsSearch(iIndex).match_type = BasicSearch
clsSearch(iIndex).Header_Operator = AndOperator
iIndex = clsSearch.Add("*")
clsSearch(iIndex).Header = "Last Name"
clsSearch(iIndex).match_type = WildCardOnly
clsSearch(iIndex).Header_Operator = OrOperator
Debug.Print clsSearch.Count
Set rResult = clsSearch.Filter
End Sub
Match Types:
MatchType.BasicSearch
MatchType.MatchCase
MatchType.MatchCase_MatchEntireCellContents
MatchType.MatchEntireCellContents
MatchType.WildCardOnly
Header Types:
HeaderOperator.AndOperator
HeaderOperator.OrOperator</pre>