Code to unfilter if filtered

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The code below works. It selects a filtered range and unfilters it.

Dim WSNames As Worksheet
Dim rng As Range
Set WSNames = Sheets("Names")
Set rng = WSNames.Range(WSNames.Range("A1"),
WSNames.Range("C1").End(xlDown))

WSNames.Select
rng.Select
ActiveSheet.ShowAllData


However, occassionally the data is not filtered at all. If the data is in
autofiltermode but nothing is filtered then it gives me an error at the
"ActiveSheet.ShowAllData" line.

I guess I need an If Then that will correct this???
 
Dim WSNames As Worksheet
Dim rng As Range
Set WSNames = Sheets("Names")
Set rng = WSNames.Range(WSNames.Range("A1"),
WSNames.Range("C1").End(xlDown))

WSNames.Select
rng.Select
if ActiveSheet.FilterMode then
ActiveSheet.ShowAllData
End if
 
Back
Top