The error ShowAllData method of Worksheet class failed
usually occurs when you try to remove an applied filter when there is not one applied.
I am not certain if you are trying to remove the whole AutoFilter
, or just remove any applied filter, but there are different approaches for each.
To remove an applied filter but leave AutoFilter
on:
If ActiveSheet.AutoFilterMode Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
The rationale behind the above code is to test that there is an AutoFilter
or whether a filter has been applied (this will also remove advanced filters).
To completely remove the AutoFilter
:
ActiveSheet.AutoFilterMode = False
In the above case, you are simply disabling the AutoFilter
completely.