[英]How to deal with autofilter using vba
enter image description here 在此处输入图片说明
I am having trouble with below line codes at line ActiveSheet.ShowAllData because at times my worksheet has the auto filter on and at times off. 我在ActiveSheet.ShowAllData行的以下行代码遇到了麻烦,因为有时我的工作表会启用自动筛选器,有时会关闭自动筛选器。 Is there a way to cater for this ??
有没有办法解决这个问题?
Consider: 考虑:
Sub Framm()
With ActiveSheet
If (.AutoFilterMode And .FilterMode) Or .FilterMode Then
.ShowAllData
End If
End With
End Sub
Note that this does not actually remove autofilters, only removes any de-selections. 请注意,这实际上不会删除自动过滤器,只会删除所有取消选择。 It will also:
它还将:
It's so much easier if you paste the code straight into your question rather than display a picture - can't copy and paste a picture into the VBE. 如果直接将代码粘贴到问题中而不是显示图片,则容易得多-无法将图片复制并粘贴到VBE中。
You need to check if anything's filtered before clearing the filter: 您需要在清除过滤器之前检查是否已过滤任何内容:
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.