Excel 2013 VBA Borrar todos los filtros macro

Parece que las macros más antiguas no funcionan. Tengo la seguridad adecuada para ejecutar macros VBA, pero cuando he probado algunos métodos para borrar TODOS los filtros en una hoja de trabajo, me da un error de compilación.

Esto es lo que he intentado:


Sub AutoFilter_Remove()
'Esta macro elimina cualquier filtro para mostrar todos los datos pero no elimina las flechas del filtro
ActiveSheet.ShowAllData
End Sub

Tengo botones en las hojas para borrar todos los filtros para facilitar el uso a los usuarios ya que las hojas tienen muchas columnas que tienen filtros.

Prueba esto:

If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData
Comentarios (3)
Solución

Si la hoja ya tiene un filtro entonces:

Sub Macro1()
    Cells.AutoFilter
End Sub

lo eliminará.

Comentarios (1)

Prueba algo así:

Sub ClearDataFilters()
'Clears filters on the activesheet. Will not clear filters if the sheet is protected.
On Error GoTo Protection
If ActiveWorkbook.ActiveSheet.FilterMode Or _
   ActiveWorkbook.ActiveSheet.AutoFilterMode Then _
   ActiveWorkbook.ActiveSheet.ShowAllData

Exit Sub
Protection:
If Err.Number = 1004 And Err.Description = _ 
    "ShowAllData method of Worksheet class failed" Then
    MsgBox "Unable to Clear Filters. This could be due to protection on the sheet.", _
    vbInformation
End If

End Sub

.FilterMode devuelve true si la hoja de trabajo está en modo filtro. (Vea esto para más información). Ver esto para más información sobre .AutoFilter.
Y finalmente, esto proporcionará más información sobre el método .ShowAllData.

Comentarios (0)