Vai al contenuto principale

Come cancellare i filtri da tutti i fogli di lavoro nella cartella di lavoro attiva in Excel?

Supponendo di aver creato più filtri su diversi fogli di lavoro in una cartella di lavoro di Excel e ora si desidera cancellare tutti questi filtri contemporaneamente. Normalmente, è necessario passare al foglio di lavoro uno per uno per controllare il filtro e quindi cancellarlo manualmente. Esiste un metodo conveniente per cancellare i filtri da tutti i fogli di lavoro in una cartella di lavoro attiva? Prova il metodo in questo articolo.

Cancella i filtri da tutti i fogli di lavoro nella cartella di lavoro attiva con codice VBA


Cancella i filtri da tutti i fogli di lavoro nella cartella di lavoro attiva con codice VBA

Si prega di eseguire lo script VBA di seguito per cancellare i filtri da tutti i fogli di lavoro nella cartella di lavoro attiva.

1. Nella cartella di lavoro da cui è necessario eliminare i filtri, premere il pulsante altro + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare clic inserire > Moduli. Quindi copia e incolla lo script VBA sottostante nella finestra del modulo. Vedi lo screenshot qui sotto:

Codice VBA: cancella i filtri da tutti i fogli di lavoro nella cartella di lavoro attiva

Sub Clear_fiter()()
'Updated by Extendoffice 20210625
    Dim xAF As AutoFilter
    Dim xFs As Filters
    Dim xLos As ListObjects
    Dim xLo As ListObject
    Dim xRg As Range
    Dim xWs As Worksheet
    Dim xIntC, xF1, xF2, xCount As Integer
    Application.ScreenUpdating = False
    On Error Resume Next
    For Each xWs In Application.Worksheets
        xWs.ShowAllData
        Set xLos = xWs.ListObjects
        xCount = xLos.Count
        For xF1 = 1 To xCount
         Set xLo = xLos.Item(xF1)
         Set xRg = xLo.Range
         xIntC = xRg.Columns.Count
         For xF2 = 1 To xIntC
            xLo.Range.AutoFilter Field:=xF2
         Next
        Next
    Next
    Application.ScreenUpdating = True

End Sub

3. premi il F5 chiave per eseguire il codice. Quindi tutti i filtri in tutti i fogli di lavoro nella cartella di lavoro corrente vengono cancellati immediatamente.


Articoli correlati:

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
@Lorif - delete For Each xWs In Application.Worksheets and one of the Nexts
This comment was minimized by the moderator on the site
Which line should I change to restrict the macro to ONLY the active sheet, rather than all of them?Much appreciated!
This comment was minimized by the moderator on the site
hi, everytime I open the file the macro runs and the filters are cleared, how to avoid that "auto run" of the macro?
This comment was minimized by the moderator on the site
Hi Juan Moreno,
I am sorry for my mistake.Replace the first line:
Sub Auto_Open()withSub Clear_filter()with solve the problem.
This comment was minimized by the moderator on the site
this removes all filters, I wanted something that would clear the filters not remove them.
This comment was minimized by the moderator on the site
Hi Saima,I got your point. The code has been updated in the post to only clear the filters instead of removing them. Please to have a try and sorry for the inconvenience.<div data-tag="code">Sub Auto_Open()
'Updated by Extendoffice 20201113
Dim xAF As AutoFilter
Dim xFs As Filters
Dim xLos As ListObjects
Dim xLo As ListObject
Dim xRg As Range
Dim xWs As Worksheet
Dim xIntC, xF1, xF2, xCount As Integer
Application.ScreenUpdating = False
On Error Resume Next
For Each xWs In Application.Worksheets
xWs.ShowAllData
Set xLos = xWs.ListObjects
xCount = xLos.Count
For xF1 = 1 To xCount
Set xLo = xLos.Item(xF1)
Set xRg = xLo.Range
xIntC = xRg.Columns.Count
For xF2 = 1 To xIntC
xLo.Range.AutoFilter Field:=xF2
Next
Next
Next
Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
Thanks this help me alot ;=)
This comment was minimized by the moderator on the site
You fucking scumbag this deleted all our filters! Our whole python script was destroyed as a result of it costing us hours! GO TO HELL YOU SCUMBAGS!!!!!!!!!!!!!!!!
This comment was minimized by the moderator on the site
You're getting free help and degrading others for your own stupid mistakes. People like you deserve a special place in hell
This comment was minimized by the moderator on the site
Why didn't you test it fully before working on your latest file and don't you have backup... work on your IT habits before using harsh language.
This comment was minimized by the moderator on the site
Hi,
Sorry for the mistake. The code has been updated in the post to only clear the filters instead of removing them. Please to have a try and sorry for the inconvenience.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations