Written by Allen Wyatt (last updated March 5, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
In testing new macros that you develop, you may find that the macro fails when it is run and the information in a worksheet is filtered. This can happen because the macro may expect that all the information in the worksheet is available, or it may try to update information that is not visible on the screen.
The best solution to this problem is to make sure that the macro turns off filtering. This can be easily done by adding the following line of code near the beginning of the macro:
ActiveWorksheet.AutoFilterMode = False
This ensures that filtering is off and removes the problems that filtered data may present for your macro. (It will, of course, result in the loss of any filtering settings, but for the purposes of many macros that may be an acceptable side effect.)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11083) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Macro Fails after AutoFilter.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
Logical structures are important in programming, as they allow you to control how the programming statements are ...
Discover MoreWhen writing a macro, you may want to fill a range of cells with different values. The easiest way to do this is to use ...
Discover MoreNormally a macro is only calculated when you specifically tell Excel to calculate it. Some macros need to be calculated ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2025-03-06 12:31:58
Richard R. M. W. Poynter
Should this not be "ActiveSheet.AutoFilterMode = False"? That worked for me whereas "ActiveWorksheet.AutoFilterMode = False" generated a Variable Not Defined error.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments