如何通过公式实现Excel过滤function?

我有一个数据表,有些数据是垃圾。 有大约30000个条目按单位sorting。 我只关心其中的20个单位。 我可以通过应用一个filter来轻松地对数据进行分类,但单击23次左右就很乏味,我将不得不每周都pipe理这个报告。

我已经将相关条件捕获到不同的工作表中,所有非重复的值被分类到一个列中。 如果单元列中的数据与条件列相匹配,我想安排另一个表格,以便只显示表格中的行。

我知道我需要使用VLOOKUP …不知怎的,但是我没有偶然发现任何将单元格的值与表格进行比较的教程。

如果这一切都非常混乱:

我的桌子:

Action | Job Desc | Dept XFR | IT Guy | Home Office 1 POS | Security Guy| Satellite Office TTL | Analyst Guy | Home Office 2 

我想有一个只包含3行的新工作表:

 Action | Job Desc | Dept XFR | IT Guy | Home Office 1 TTL | Analyst Guy | Home Office 2 

我把“家庭办公室1”和“家庭办公室2”的价值存储在其他地方(实际上有28个不同的办公室值)。 我如何build立这个表,所以它只显示这些值 – 类似的股票Excel的过滤function?

我认为最简单的方法是创build一个“有趣”的单位,并查看这个选项卡。 在新的感兴趣的标签中,您将列出您感兴趣的A列中的20个项目。

在包含所有30,000行的数据选项卡中,如果存在于感兴趣的选项卡中,则需要添加一个新列来检查每一行。 我假设这些单位在列C中,并且您正在单元格D1 =NOT(ISERROR(VLOOKUP(C1,InterestingTab!A:A,1,0)))中input此公式。

公式的结果是TRUE或FALSE,可以很容易地过滤。 然后,您可以轻松地将新项目添加到有趣的选项卡,并自动更新。

一个非常普遍的问题。

假如说:

1)您正在使用Excel 2010或更高版本

2)原始表格在Sheet1!A1:C10 (在第1行中有标题)

3)容纳(过滤的)结果的表格在Sheet2并且与原始表格具有相同的布局

4)(28)标准清单在Sheet3!A2:A29

然后在Sheet2!J1input这个公式Sheet2!J1

=SUMPRODUCT(COUNTIF(Sheet3!A2:A29,Sheet1!C2:C10))

当然,单元格的select并不一定是J1,但是,无论您select什么,请确保它是一个在结果表格外部的单元格。 这个公式是一次性的,不像主结果表中那样,不是被devise成被复制到任何更多的单元格; 它只是确定预期回报的数量,并将在主表公式中被引用,从而避免资源IFERROR设置。

结果表单元格A2中的公式是:

=IF(ROWS($1:1)>$J$1,"",INDEX(Sheet1!A:A,AGGREGATE(15,6,ROW(Sheet1!B$2:B$10)/MATCH(Sheet1!$C$2:$C$10,Sheet3!$A$2:$A$29,0)^0,ROWS($1:1))))

并根据需要向下复制。

显然,如果原始表格中的上一行参考实际上不是10,那么您将需要相应地修改这些公式中的那个部分。 但是,一定不要select一个任意大的值,因为对于每个引用的附加单元,将需要额外的计算(无论那些附加单元在技术上是否超出这些范围中的最后使用的单元,都适用)。

因此,我build议您select一个适当的低,尽pipe足够的,对于引用的最后一行的上限,或者甚至更好,使您的范围dynamic,使他们自动调整为您的数据展开/合同。

问候

这是我的…

 Sub takeMyValus() Dim r1 Dim r2 Dim c Dim rng1 As Range Dim rng2 As Range Dim sht1 As Worksheet Dim sht2 As Worksheet Dim sht3 As Worksheet Dim List() Dim i Dim j r1 = Range("A1").End(xlDown).Row 'to know the last row c = Range("A1").End(xlToRight).Column 'to know the last colum Set sht1 = Sheets("Data") 'this is the name I used, but you 'put the name of your data sheet Set sht2 = Sheets("List") 'the sheet with the sorted list of the data you want sht1.Activate 'Just in case Set rng1 = Range(Cells(1, 1), Cells(r1, c)) 'set just the range with data rng1.AutoFilter 'set the autofilter 'is better if the data has no autofilter 'when you begin to run the macro sht2.Activate 'imagine that you got the list in column A and is just 5 items in your data 'With no header '+---------+ '| Office3 | '| Home5 | '| Office8 | '| Home8 | '| Sat2 | '+---------+ 'List for my example... r2 = Range("A1").End(xlDown).Row 'to know the total item on the list 'in this case will be 5 Set rng2 = Range(Cells(1, 1), Cells(r2, 1)) 'set the range of the list 'that is Range("A1:A5") j = 0 'ini the counter For Each i In rng2 'for every cell in Range("A1:A5") j = j + 1 'increase the j to 1 every time ReDim Preserve List(1 To j) 'redimension the var... List(j) = i.Value 'store every cell (just the data) into an array Next i 'next one. sht1.Activate 'go to sheet with all the data rng1.AutoFilter Field:=3, Criteria1:=Array(List), Operator:=xlFilterValues 'set the filter with the list rng1.SpecialCells(xlCellTypeVisible).Copy 'copy just the cells that you can see, this is the filter Sheets.Add after:=Sheets(Sheets.Count) 'add a new sheet ActiveSheet.Name = myTime 'put a diferent name, see the function below Set sht3 = ActiveSheet 'store the new sheet into this var sht3.Activate 'go to the new sheet... is already activate, but just in case... Range("A1").PasteSpecial xlPasteAll 'paste all in Range("A1") Application.CutCopyMode = False 'is like press ESCAPE in the keyboard End Sub Function myTime() As String 'the function a told you Dim HH Dim MM Dim SS Dim TT HH = Hour(Now) MM = Minute(Now) SS = Second(Now) myTime = Format(HH, "00") & Format(MM, "00") & Format(SS, "00") End Function 

这是我的数据的例子…

 +--------+---------+----------+ | Action | Job Des | Dept | +--------+---------+----------+ | XFR | IT | Office1 | | POS | Sec | Office2 | | TTL | Analyst | Office3 | | XFR | IT | Office4 | | POS | Sec | Office5 | | TTL | Analyst | Office6 | | XFR | IT | Office7 | | POS | Sec | Office8 | | TTL | Analyst | Office9 | | XFR | IT | Office10 | | POS | Sec | Home1 | | TTL | Analyst | Home2 | | XFR | IT | Home3 | | POS | Sec | Home4 | | TTL | Analyst | Home5 | | XFR | IT | Home6 | | POS | Sec | Home7 | | TTL | Analyst | Home8 | | XFR | IT | Home9 | | POS | Sec | Home10 | | TTL | Analyst | Home11 | | XFR | IT | Home12 | | POS | Sec | Sat1 | | TTL | Analyst | Sat2 | | XFR | IT | Sat3 | | POS | Sec | Sat4 | | TTL | Analyst | Sat5 | | XFR | IT | Sat6 | | POS | Sec | Sat7 | | TTL | Analyst | Sat8 | | XFR | IT | Sat9 | | POS | Sec | Sat10 | | TTL | Analyst | Sat11 | | XFR | IT | Sat12 | | POS | Sec | Sat13 | | TTL | Analyst | Sat14 | +--------+---------+----------+ 

列表

 +---------+ | Office3 | | Home5 | | Office8 | | Home8 | | Sat2 | +---------+ 

结果:

 +--------+---------+---------+ | Action | Job Des | Dept | +--------+---------+---------+ | TTL | Analyst | Office3 | | POS | Sec | Office8 | | TTL | Analyst | Home5 | | TTL | Analyst | Home8 | | TTL | Analyst | Sat2 | +--------+---------+---------+