简体   繁体   中英

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. 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.

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.

I have tried the FILTER function, No it doesn't work in MS Excel 2013. I also reviewed VLOOKUP, nope. I know PIVOT is not what i want. I want to avoid VBA scripting because this will go to a non-developer eventually.

Lastly filter the current table will not meet my objective.

The Advanced Filter will only copy to the same worksheet.

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.

Then use this to INDEX into the array, and IFERROR to take care of dragging the formula down more rows than are present.

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.

在此处输入图像描述

在此处输入图像描述

Multiple roads to Rome here, but let's assume this sample data on Sheet1 :

在此处输入图像描述


Formulas (just an example)

This is my result on Sheet2 :

在此处输入图像描述

Formula in 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

Drag down and right


AdvancedFilter (as you seem interested in that option too)

Just to add this option (involves some manual labour though)

If you set up your second sheet like so:

在此处输入图像描述

Formula in A2 :

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

Formula in 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. 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 :

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. 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.


在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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