通过列search来给出一个项目的历史

我在我的Excel表格中有几列。 我的实际工作表要复杂得多,我有一个静态的macros。 然而,这是关于search指定的值,然后列出所有search的内容…

所以你有这个:

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 

我想创build一个searchfunction,你键入的types ,它列出了该types的所有信息。

举个例子:

 Search: cat 

用户只需input猫,并被给予

  cat 123651 11/7/14 1:00 pm cat 123451 11/3/14 1:00 pm 

希望…这可以以某种方式完成。

类似barrowc说的,最好的方法是使用内置的Autofilter。 但是,如果你想做一些总是可见的自定义search框,你可以使用一些VBA(H5是你的search框):

 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 

这将更改自动筛选器以search您的search单元格的当前值。

注意:未经testing的伪代码

http://trumpexcel.com/2015/01/dynamic-excel-filter/

对于任何想在没有VBA的excel表格中创build一个字面search栏的人,请点击此链接。

其他的评论也很好,但这完全避免了VBA。

感谢大家的帮助。