Excel – 按date筛选表格结果

我在Excel中有一个可刷新的表,我想通过几个date范围过滤行。 每一行都有一个date和其他信息。

我想要查找在第一个date范围(F1:F2),不在第二个date范围(H1:H2)中的行。

桌子是可刷新的,并且可以改变大小。 它目前跨越A3:X6146。 该表是一个查询,因此当使用单独的date范围来查找表值时,它将更改大小。

我没有太多的VBA经验,所以这个问题让我失望。 有任何想法吗?

谢谢

编辑:

我会尽力使问题更清楚。

我有一个表是通过一个查询来创build的,这个查询包含起始date和结束date,2016年1月1日和12/31/2017之间的数据。 它每次列出一个项目被购买,所以每一个可以列出多次。

我想要查找在活动date范围的开始date和结束date(单元格F1和F2)之间购买哪些项目(在表中列出),而不是在非活动date范围(单元格H1和H2)之间购买的项目。

Starting Date: 1/1/2016 Active Date Range Start: 3/1/2016 Inactive Date Start: 3/2/2017 Ending Date: 12/31/2017 Active Date Range End: 3/1/2017 Inactive Date End: 9/22/2017 item date 1 9/21/2017 2 9/20/2017 3 9/20/2017 

是的,我可以告诉你我会做什么。

创build一个额外的列来保留结果值,如果在date范围之内或之外。 然后

 dim t() as string, lin as long, linf as long linf=Range("F65536").End(xlUp).Row 'or any other more precise way to get the final line redim t(1 to linf-2,1 to 1) 'range dates - are they on the worksheet? dim rg_dates as Range,r as range,b as boolean set rg_dates=Sheets("xxxx").Range("B1:B4") ' just an example, the range would be B1:C4 but use only the first column - see below For lin=3 to linf b=False For each r in rg_dates If cells(lin,"F").value>= r.Cells(1,1) and cells(lin,"G").Value<=r.Cells(1,2).value then b=true Exit for End If Next r If b then t(lin-2,1)="Y" else t(lin-2,1)="N" Next l Range("Z3:Z" & linf).Value = T 

“然后只是过滤表。

那么要保证它没有错误,还有很多事情要做,如何在具体的情况下应用它。 希望以上我写的内容可以了解使用VBA可以做的事情。 如果使用代码来过滤表格,则可以对用户执行所有这些操作,为过滤条件创build额外的列,然后进行筛选,然后删除整个列。