[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Auto Filter Macro Help - Rewrite code

Posted on 2009-12-23
4
Medium Priority
?
173 Views
Last Modified: 2012-05-08
I have a code below that remove auto filter. But I wrote the code incorrectly.

Please help rewrite it. The purpose of the code is: if the sheet has auto filter then turn it off.

THanks,
Sub FilterOff()

    'XXXXX Turn off auto filter XXXXXXXXXX
    Dim ws As Worksheet
  ws = ActiveWorkbook.Worksheets
  If ws.Worksheets.AutoFilterMode Then Selection.AutoFilter
    'xXXX Turn off auto filter XXXXXXXXXXXXXXXX

End Sub

Open in new window

0
Comment
Question by:Mighty1072
  • 3
4 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 26113613
Hello Mighty1072,

Try something like this for the active sheet

Regards,

chris_bottomley
Sub FilterOff()

    'XXXXX Turn off auto filter XXXXXXXXXX
Dim ws As Worksheet
    Set ws = ActiveSheet
    If ws.AutoFilterMode Then Selection.AutoFilter
    'xXXX Turn off auto filter XXXXXXXXXXXXXXXX

End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26113629
Mighty1072,

For all sheets it would be more like:

chris_bottomley
Sub FilterOff()
Dim ws As Worksheet

    'XXXXX Turn off auto filter XXXXXXXXXX
    For Each ws In ThisWorkbook.Worksheets
        If ws.AutoFilterMode Then Selection.AutoFilter
    Next
    'xXXX Turn off auto filter XXXXXXXXXXXXXXXX

End Sub

Open in new window

0
 

Author Comment

by:Mighty1072
ID: 26113639
work great!!!! Thanks,
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 26113673
Glad to help

Chris
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question