[英]Automatically Sort Excel Columns When Data Changes - But With No Assumptions About My Data
Here is my situation:这是我的情况:
How can I make the spreadsheet automatically apply the filters and sorting whenever data is changed?如何让电子表格在数据更改时自动应用过滤器和排序?
Any solution I can find online requires you to manually modify the VBA code to make it work with your specific data.我可以在网上找到的任何解决方案都需要您手动修改 VBA 代码以使其适用于您的特定数据。 You need to change things like: the range your data is in, the columns that need to be filtered by, the sorting that needs to be applied, etc, etc.
您需要更改以下内容:数据所在的范围、需要过滤的列、需要应用的排序等。
Some examples that I have found that don't live up to my expectations are here , here , and here我发现的一些不符合我期望的例子在这里, 这里和这里
Is there a script that I could drop into any Excel spreadsheet that meets my requirements?是否有可以放入任何满足我要求的 Excel 电子表格的脚本?
I do not have possibility to check it now but adding any new criteria to existing filter and then removing it should re-filter the range.我现在无法检查它,但是向现有过滤器添加任何新标准然后删除它应该重新过滤范围。 Maybe the same would do with sorting.
也许排序也是如此。
It could be triggered by worksheet_change() event.它可以由 worksheet_change() 事件触发。
This works when your filter is applied to ListObject:当您的过滤器应用于 ListObject 时,这会起作用:
Private Sub Worksheet_Change(ByVal Target As Range)
Target.ListObject.AutoFilter.ApplyFilter
End Sub
and does the thing with sorting as well.并且也做排序的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.