简体   繁体   中英

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

  • not barf if all data is already showing
  • not barf if filtering not is present.

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.

You need to check if anything's filtered before clearing the filter:

If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData

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