ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If autofilter is on, then.. (https://www.excelbanter.com/excel-programming/369192-if-autofilter-then.html)

Darin Kramer

If autofilter is on, then..
 
Guys,

My Macro needs to autofilter on row 2.
Problem is I need to tell Excel to look whether there currently is an
existing autofilter on or not. (My code below says selction.autofilter -
ie if there is NO autofilter it correctly turns Autofilter on and works
fine, BUT sometimes there is an existing autofilter turned on, so all
the code does is turn the existing autofilter off, ie it does nothing.

Ideas...?

Thanks
D

sub filter
'turn autofilter on
ActiveSheet.Select
Rows("2:2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="ASPAC"
Range("c3").Select

End sub

*** Sent via Developersdex http://www.developersdex.com ***

Dave Peterson

If autofilter is on, then..
 
If you're going to add the autofilter arrows, you can remove them first:

activesheet.autofiltermode = false

It won't hurt if there is no filter applied, too.

Then just apply it where you want.

Darin Kramer wrote:

Guys,

My Macro needs to autofilter on row 2.
Problem is I need to tell Excel to look whether there currently is an
existing autofilter on or not. (My code below says selction.autofilter -
ie if there is NO autofilter it correctly turns Autofilter on and works
fine, BUT sometimes there is an existing autofilter turned on, so all
the code does is turn the existing autofilter off, ie it does nothing.

Ideas...?

Thanks
D

sub filter
'turn autofilter on
ActiveSheet.Select
Rows("2:2").Select
Selection.AutoFilter
Selection.AutoFilter Field:=4, Criteria1:="ASPAC"
Range("c3").Select

End sub

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson

Darin Kramer

If autofilter is on, then..
 


Thanks Dave - works perfectly

*** Sent via Developersdex http://www.developersdex.com ***


All times are GMT +1. The time now is 03:02 AM.

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