Sub MaurizioInputFilter()
'Crafted by Wookiee @ MrExcel.com
Dim strFilter As String
Dim rngFiltration As Range
Dim wksHome As Worksheet
If wksHome Is Nothing Then
Set wksHome = ActiveSheet
End If
Set rngFiltration = wksHome.Range("$A$2:$A$51")
strFilter = VBA.InputBox _
("Enter your filter criterion:")
strFilter = "=*" & strFilter & "*"
rngFiltration.AutoFilter _
Field:=1, _
Criteria1:=strFilter
End Sub
Operator:=xlFilterValues
option of autofilter.OK, thanks!You can't use wildcard filters with numbers. Unless you can store all the data as text, your code will have to loop through all the data and build up an array of values that contain the value you are interested in, then use that array with theOperator:=xlFilterValues
option of autofilter.
Sub AdvFltr()
Dim rCrit As Range
Dim strFilter As String
strFilter = Application.InputBox("Enter your filter criterion:")
Set rCrit = Range("Z1:Z2")
rCrit.Cells(2).Formula = Replace("=Find(""#"", A2)", "#", strFilter)
Intersect(ActiveSheet.UsedRange, Columns("A")).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
rCrit.Cells(2).ClearContents
End Sub