Posted in: E Learn

Mastering Excel- Advance Filter Using Macro

Creating a macro with the Advanced Filter feature in MS Excel involves several steps. Here’s a step-by-step guide to help you through the process:

Step 1: Prepare Your Data

Ensure your data is well-organized, with column headers in the first row and no blank rows or columns within the data range.

Step 2: Set Up Criteria Range

Define the criteria range. This range must include the column headers and the conditions you want to apply.

  1. Criteria Range Example:
    • Suppose you have a data range in A1:C10 with headers Date, Product, and Sales.
    • Your criteria range might be E1:F2 where:
      • E1 = Product
      • F1 = Sales
      • E2 = Widget
      • F2 = >1000

Step 3: Record a Macro

  1. Open the Developer Tab:
  • If the Developer tab is not visible, enable it by going to File > Options > Customize Ribbon and checking the Developer option.
  1. Start Recording:
  • Click on Developer > Record Macro.
  • Give your macro a name, such as AdvancedFilterMacro.
  • Optionally, assign a shortcut key and choose where to store the macro (This Workbook is typical).
  • Click OK to start recording.

Step 4: Apply the Advanced Filter

  1. Select Your Data Range:
  • Click and drag to select the range of data you want to filter (e.g., A1:C10).
  1. Open Advanced Filter:
  • Go to Data > Sort & Filter > Advanced.
  1. Set Advanced Filter Options:
  • In the Advanced Filter dialog box, choose either Filter the list, in-place or Copy to another location.
  • If copying to another location, specify the destination range.
  • Set the List range to your data range (e.g., A1:C10).
  • Set the Criteria range to your criteria range (e.g., E1:F2).
  • Click OK to apply the filter.
See also  Advance Microsoft Excel Syllabus

Step 5: Stop Recording the Macro

  • Go to Developer > Stop Recording.

Step 6: Test the Macro

  1. Clear Any Existing Filters:
  • Ensure there are no filters applied to your data.
  1. Run the Macro:
  • Press the shortcut key you assigned or go to Developer > Macros, select your macro, and click Run.

Step 7: Edit the Macro (Optional)

If you need to make adjustments to the macro, you can edit it in the VBA editor.

  1. Open VBA Editor:
  • Go to Developer > Visual Basic.
  1. Find Your Macro:
  • In the Project Explorer, find your workbook and open Modules.
  • Double-click on Module1 (or the module where your macro is stored).
  1. Edit the Code:
  • Modify the macro code as needed. Here’s an example of what the recorded macro might look like:
Sub AdvancedFilterMacro()
    Range("A1:C10").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:F2"), Unique:=False
End Sub

Step 8: Save Your Workbook

  • Save your workbook as a macro-enabled workbook by selecting File > Save As and choosing Excel Macro-Enabled Workbook (*.xlsm).

Summary

By following these steps, you can create a macro in Excel that uses the Advanced Filter feature to automate data filtering based on specified criteria. This macro can save time and ensure consistency when applying complex filters to your data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top