VBA - EXCEL - AutoFilter and Object Range Method

January 2017

One may need several types of filters in an Excel sheet to help with VBA programming. An Excel sheet is used to simplify tedious calculations and setting filters are important in the process. This will help in setting a range in Excel by using simple programs in VBA. The main query people have is how to retrieve objects in an object range format. The article below is a small VBA programming lesson on selecting an auto filter and object range in the field of a particular cell in an Excel sheet. Initiate it by starting a macro and end the sub VBA program. The cells must be active and not hidden by filters.


With VBA programming, it is possible to set filters on a sheet:
  • Selection.AutoFilter Field:=1, Criteria1:="FOO"
  • The filter displays a certain number of lines based on defined criteria.
  • How to retrieve these rows in a Range objects?


This should answer your problem:

Sub Macro2 ()      
    Sun rngSelect As Range      
    'I assumed that the filters are on line 1      
    Range ( "A1"). Select      
    'Selection.AutoFilter Field: = 1, Criteria1: = "FOO"      
    Selection.AutoFilter Field: = 7 Criteria1: = "* paris *"      
    'RngSelect = all cells visible (not hidden by the filter)      
    'Contiguous to the active cell      
    Set rngSelect = ActiveCell.CurrentRegion.SpecialCells (xlCellTypeVisible)      
    'Copy the selected area      
    Debug.Print rngSelect.Address      
    'Many and varied      
    Set rngSelect = Nothing      
End Sub


Published by aakai1056. Latest update on March 19, 2012 at 08:39 AM by Virginia Parsons.
This document, titled "VBA - EXCEL - AutoFilter and Object Range Method," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).