Code to unfilter if filtered

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???
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top