问题
Hi I am new to using dynamic search boxes to filter in excel. I have a large dataset that I want to be able to type in any value from the a multi column table and all data with that value will be returned.
I have turned the whole dataset into a table and used concat formula at the end of the table. The formula for which is: =CONCAT(Table4[@[Currency Description]:[SUM No. Data Submissions]]& "")
Currency Description being mt first column, SUM No. Data Submissions the last.
This for some reason returns the #value error code I am not sure why.
I think this is why my code is then not working. Theoretically this should allow me to type any text in the cell range "search_string" which should return what I am after. I am not sure why this is not working, any help would be great thanks. The code I have is the following:
Dim KeyCells As Range
Set KeyCells = Range("search_string")
If Not Application.Intersects(KeyCells, Range(Target.Address)) _
Is Nothing Then
FastFilter (KeyCells.Value)
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
Sub FastFilter(sch As String)
Dim lo As ListObject
Set lo = ActiveSheet.ListObjects(4)
'ListObjects(4) relates to column
lastcol = lo.ListColumns.Count
If lo.AutoFilter.FilterMode Then
lo.AutoFilter.ShowAllData
lo.Range.AutoFilter Field:=lastcol, Criteria1:= _
Array("*" + sch + "*"), Operator:=xlFilterValues
Else
lo.Range.AutoFilter Field:=lastcol, Criteria1:= _
Array("*" + sch + "*"), Operator:=xlFilterValues
'* adds wild card search
End If
Range("search_string").Select
End Sub ```
来源:https://stackoverflow.com/questions/62883310/dynamic-filter-using-excel-vba