VBA AdvancedFilter in Excel - Explained with Examples

Advanced filters are very powerful and useful while dealing or filtering the data with verity of conditions. We can apply Advanced Filters using VBA. We can copy the data into another location or we ca filter the data in the same location.
VBA AdvancedFilter Method Excel Range Object

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Excel VBA Range Advanced Filter – Syntax

Here is the syntax or VBA code to apply the advanced filter in a range of data.

Range(“YourRange”).AdvancedFilter(Action As XlFilterAction,

[CriteriaRange], [CopyToRange], [Unique])

  • Here AdvancedFilter is a Member of Excel.Range Object.
  • XlFilterAction: You can specify how you want perform the filter:
    • Const xlFilterInPlace = 1 will filter in the range data source.
    • Const xlFilterCopy = 2 will filter the data and copy to the target range, in this case you have to provide the [CopyToRange] which you want to copy the filtered data.
  • [CriteriaRange]: You can specify the filter criteria range where you can mention any criteria including formulas.
  • [Unique]: You can set to TRUE if you want to get unique records, False to set all records.

Excel VBA Range Advanced Filter- Examples

Here is the simple example to apply the advanced filer in a range. Assuming that you have data in Range “A3:B8” and You have specifies the criteria at Range “B1:B2”. Here we are using xlFilterInPlace to filter the data in the data range itself. and no need to provide the target range.

Sub VBA_Range_Advanced_Filter()
Range("A3:B8").AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=Range("B1:B2"), Unique:=False
End Sub

Excel VBA Range Advanced Filter- Instructions

Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:

  1. Open an Excel Workbook from your start menu or type Excel in your run command
  2. Now you have to prepare some sample data to test this macro.
  3. Enter the header as SerialNumber at A3 and Value at B3)

  4. Enter some sample data from range A4 to B8, say 1 to 5 in SerialNumber and 100 to 500 in values fileld
  5. Now enter the criteria, I am entering at ‘SerialNumber’ at Range B1 and ‘>2’ as criteria at Range B2. So your criteria range will be “B1:B2”
  6. Press Alt+F11 to Open VBA Editor or you can goto Developer Table from Excel Ribbon and click on the Visual Basic Command to launch the VBA Editor
  7. Insert a Module from Insert Menu of VBA
  8. Copy the above code (for filtering the data in a range using Excel VBA) and Paste in the code window(VBA Editor)
  9. Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
  10. Press ‘F5′ to run it or Keep Pressing ‘F8′ to debug the code line by line.

Now, You can observe that the records are displaying only for values 3,4 and 5.

Real-time Applications on Excel VBA Range Advanced Filters

Hide Developer Tab in Excel Ribbon

Hide Developer Tab in Excel Ribbon using from the Excel options. It helps to prevent users from opening the Excel VBA editor window. Hide Developer Tab in Excel Ribbon: Right click on any main menu

  • Excel UserForm show hide unload

Show or Hide|Unload a userform

Show or hide means to display or hide a Userform. We use Show and Hide methods to display or hide. Unload will be used when completes the task.

  • Column Number to Column Name

Column Number to Column Name

Column Number to Column Name is nothing but converting column number to Excel alphabetic character column name. Most of the time while automating many tasks using Excel VBA, it may be required.

  • Column Number to Column Name

Column Name to Column Number

Column Name to Column Number is nothing but converting Excel alphabetic character column name to column number. Most of the time while automating many tasks it may be required. Please find the following details about conversion of column name to column number. You can also say column string to column number. Or get alphabetic character to column number using Excel VBA.

  • remove checkbox on worksheet or userform

Remove CheckBox on Worksheet or UserForm in Excel

We can remove or delete checkbox on the worksheet or userform using ‘Go To Special’ or ‘Select Objects’ or by turning on Design Mode in Developer tab. when we don’t want to place checkbox control on the worksheet or userform we removes from there. Please find the more details and screenshots for clear understanding about remove checkbox control in the following chapter.

  • vba to add checkbox on worksheet or userform

Add CheckBox on Worksheet or UserForm using VBA

We can add CheckBox on Worksheet or UserForm is using VBA with checkbox control and is used to specify or indicate boolean choice. In this section we will see how to add single checkbox or multiple checkboxes on the worksheet or userform using VBA. Please find the more details about add checkbox control using VBA in the following chapter.

  • add checkbox on worksheet or userform

Add CheckBox on Worksheet or UserForm in Excel

Add CheckBox on Worksheet or UserForm is using checkbox control and is used to specify or indicate binary choice. In this section we will see how to add single checkbox or multiple checkboxes on the worksheet or userform. Please find more details about add checkbox control in the following chapter.

  • Excel VBAOptimize VBA Code to run Macros Faster

Optimize VBA Code to run Macros Faster

Optimize VBA code to run macros faster, simple, easy to understand and efficient way of writing macro. Please find the more details and examples.

  • Excel VBA Develoer Tab1

Show Developer Tab in Excel Ribbon

Developer Tab in MS Office tools helps programmer to navigate VBA editor, recording macros to automate repetitive tasks and to write VBA programs to develop applications.

  • VBA Copy Worksheet

Copy Worksheet

Copy worksheet in VBA is used to Copy the worksheet from one location to another location in the same workbook or another new workbook or existing workbook.

LIMITED TIME OFFER

Leave A Comment