Create Data Filters in Microsoft Excel using VB Macro


Create Data Filters in Microsoft Excel using VB Macro




In this article, I will explain how to create a data filter in Microsoft Excel using VB Macro. I use the vehicle data example. let's start.


  1. First make 1 excel file with 2 sheets, as shown below.

    In sheet 1, block all data and groups with the name "data".
    in sheet 2, block the Vehicle Condition column and the group named "Criteria". 
    in sheet 2, block row (only the table header is blocked) Vehicle Condition, Type and Vehicle Name and Group with the name "Result".

  2. Click the Developer Tab menu. If you don't have a Developer menu, you can activate it in the File menu -> Options -> Customize Ribbon and activate the Developer menu in the Main Tabs window. 


  3. Click the Developer tab menu. Click the Controls (View Code) submenu, the Visual Basic window will appear. Click the Insert tab menu -> click Module, then the module will be added to the project layer window. 
    Click on the module. move your cursor to the coding window and type the Visual Basic code using the AdvancedFilter function. Ctrl+S 👈😇

    Sub VbaAdvancedFilter()
    Range("data").AdvancedFilter Action:=xlFilterCopy, criteriarange:=Range("Criteria"), copytorange:=Range("Result"), Unique:=False
    End Sub
  4. Back to Excel, sheet 2, click the Developer menu tab -> Insert sub menu -> Form Control (Button), click where to place the button you want. Select Macro (VbaAdvancedFilter) then click OK. Name the button up to you.


  5. Fill in the criteria "Good" then press the Go button ... congratulations. You can already use the VB AdvancedFilter function 

Comments