ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to unfilter if filtered (https://www.excelbanter.com/excel-programming/382388-code-unfilter-if-filtered.html)

Shawn

Code to unfilter if filtered
 
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???


--
Thanks
Shawn

Tom Ogilvy

Code to unfilter if filtered
 
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

--
Regards,
Tom Ogilvy


"Shawn" wrote:

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


--
Thanks
Shawn



All times are GMT +1. The time now is 01:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com