我的excel表中有几列如此。我的实际工作表要复杂得多,我有一个静态时间的宏。然而,这是关于搜索指定的值,然后列出搜索的所有内容......
所以你有这个:
type item# date
cat 123451 11/3/14 1:00 pm
dog 154321 12/3/14 2:00 pm
fish 999900 10/4/12 4:00 pm
cat 123651 11/7/14 1:00 pm
dog 154621 12/8/14 2:00 pm
fish 992900 10/1/12 3:00 pm
我想创建一个搜索功能,您可以在其中键入 类型 ,并列出该类型的所有信息。
以此为例:
Search: cat
用户只需键入cat并获得
cat 123651 11/7/14 1:00 pm
cat 123451 11/3/14 1:00 pm
希望......这可以通过某种方式完成。
答案 0 :(得分:1)
与barrowc所说的相似,最好的方法是使用内置的自动过滤器。但是,如果你想做一些始终可见的自定义搜索框,你可以使用一些VBA(H5是你的搜索框):
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("H5")) Is Nothing Then
'Executes on cell change
Dim criteria as Range
Set criteria = Range("H5")
'Range below is the total range of all your data to sort
'Field is the index of your column you want to sort by (Type)
Range("A1:D1").AutoFilter Field:=1, Criteria1:=criteria.Value
End If
End Sub
这将更改自动过滤器以搜索搜索单元格的当前值。
注意:未经测试的伪代码
答案 1 :(得分:0)
http://trumpexcel.com/2015/01/dynamic-excel-filter/
对于那些希望在没有VBA的Excel工作表中创建字面搜索栏的人,请点击此链接。
其他评论也很好,但这完全避免了VBA。
感谢大家的帮助。