简体   繁体   English

按日期范围在新选项卡上显示的过滤列表

[英]A filtered list displayed on a new tab by date ranges

Excel has been out of my scope for a long time, and this feels very simple. Excel已经出我的scope很久了,这个感觉很简单。 Looking for the formula to filter a list, but the results are on a new tab.正在寻找过滤列表的公式,但结果在新选项卡上。

Closest thing I have found is this FILTER function, but as the site reads it's a new feature to be released in 2019. So I do not have access to it because I'm using Excel 2013.我发现的最接近的东西是这个FILTER function,但在网站上看到它是 2019 年发布的新功能。所以我无法访问它,因为我使用的是 Excel 2013。

I'm trying to filter on a field of Date Ranges, so all entries in the current week would be filtered to the new tab.我正在尝试过滤日期范围的字段,因此本周的所有条目都将被过滤到新选项卡中。

在此处输入图像描述

So filter with dates for the week of 06 Oct 2019 to 12 Oct 2019 on a new tab would return the top 2 rows only.因此,在新选项卡上过滤 2019 年 10 月 6 日至 2019 年 10 月 12 日这一周的日期将仅返回前 2 行。

I have tried the FILTER function, No it doesn't work in MS Excel 2013. I also reviewed VLOOKUP, nope.我已经尝试过 FILTER function,不,它在 MS Excel 2013 中不起作用。我还查看了 VLOOKUP,不。 I know PIVOT is not what i want.我知道 PIVOT 不是我想要的。 I want to avoid VBA scripting because this will go to a non-developer eventually.我想避免 VBA 脚本,因为这最终将 go 给非开发人员。

Lastly filter the current table will not meet my objective.最后过滤当前表将不符合我的目标。

The Advanced Filter will only copy to the same worksheet. Advanced Filter只会复制到同一个工作表。

For a formula, you can create an array of relevant row numbers and return them, in order, using the AGGREGATE function using the Small function and the option to ignore errors.对于公式,您可以使用AGGREGATE function 使用Small function 和忽略错误的选项创建相关行号数组并按顺序返回它们。

Then use this to INDEX into the array, and IFERROR to take care of dragging the formula down more rows than are present.然后使用它来INDEX到数组中,并使用IFERROR来处理将公式向下拖动的行数超过现有行数。

For example, using Tables and structured references: In the upper right cell of where you want the results:例如,使用表格和结构化引用:在您想要结果的右上方单元格中:

=IFERROR(INDEX(Table1_2,AGGREGATE(15,6,1/((Table1_2[[Dates]:[Dates]]>=From)*(Table1_2[[Dates]:[Dates]]<=To))*ROW(Table1_2)-ROW(Table1_2[#Headers]),ROWS($1:1)),COLUMNS($A:A)),"")

Fill right and down to fill your matrix and the references should self-adjust.向右和向下填充以填充您的矩阵,并且参考应该自我调整。

Change the Table to whatever your table is named, or use absolute addressing.Table更改为您的表的名称,或使用绝对寻址。

在此处输入图像描述

在此处输入图像描述

Multiple roads to Rome here, but let's assume this sample data on Sheet1 :这里有多条通往罗马的道路,但让我们假设Sheet1上的示例数据:

在此处输入图像描述


Formulas (just an example)公式(只是一个例子)

This is my result on Sheet2 :这是我在Sheet2上的结果:

在此处输入图像描述

Formula in A2 : A2中的公式:

=IFERROR(INDEX(Sheet1!A$1:A$10,SMALL(IF((Sheet1!$A$2:$A$10>=TODAY()-WEEKDAY(TODAY(),2)+1)*(Sheet1!$A$2:$A$10<=TODAY()-WEEKDAY(TODAY())+7)=1,ROW(Sheet1!$A$2:$A$10),""),ROW(A1))),"")

Note: It's an array formula and needs to be entered through Ctrl Shift Enter注意:是数组公式,需要通过Ctrl Shift Enter 输入

Drag down and right向下和向右拖动


AdvancedFilter (as you seem interested in that option too) AdvancedFilter (您似乎也对该选项感兴趣)

Just to add this option (involves some manual labour though)只是添加这个选项(虽然涉及一些体力劳动)

If you set up your second sheet like so:如果您像这样设置第二张工作表:

在此处输入图像描述

Formula in A2 : A2中的公式:

=">="&TEXT(TODAY()-WEEKDAY(TODAY(),2)+1,"yyyy/mm/dd")

Formula in A3 : A3中的公式:

="<="&TEXT(TODAY()-WEEKDAY(TODAY(),2)+1,"yyyy/mm/dd")

Now, it's important to initiate AdvancedFilter from the sheet you want to pull data into.现在,从要将数据拉入的工作表中启动AdvancedFilter很重要。 And assign the appropriate ranges并分配适当的范围

Result looks like:结果如下:

在此处输入图像描述

To auto-update this AdvancedFilter , you need a simple piece of VBA, so paste the following as a Worksheet_Change() event on Sheet1 :要自动更新此AdvancedFilter ,您需要一个简单的 VBA ,因此将以下内容粘贴为Sheet1上的Worksheet_Change()事件:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng1 As Range, rng2 As Range
Dim lr1 As Long, lr2 As Long

With Sheet1
    lr1 = .Cells(.Rows.Count, 1).End(xlUp).Row
    Set rng1 = .Range("A1:C" & lr1)
End With

With Sheet2
    lr2 = .Cells(.Rows.Count, 1).End(xlUp).Row
    If lr2 > 3 Then
        Set rng2 = .Range("A5:C" & lr2)
        rng2.ClearContents
    End If
    rng1.AdvancedFilter xlFilterCopy, .Range("A1:C3"), .Range("A5")
End With

End Sub

Now you'll be able to add data in Sheet1 and it will auto-update the AdvancedFilter , which will be fast.现在您可以在Sheet1中添加数据,它会自动更新AdvancedFilter ,这会很快。 But if you want to stay away from VBA, definately go with the formulas provided by either myself, or the more efficient approach with a ListObject by @RonRosenFeld.但是,如果您想远离 VBA,肯定是 go 使用我自己提供的公式,或者使用@RonRosenFeld 提供的 ListObject 更有效的方法。


在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM