Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to filter in excel vba?

Filter In Column Using Text Boxes

A nice filtering template.

The value in textbox is searched as part or whole in the column.

The results found are shown in the column, the other data are hidden.

 Review tutorial's video and download sample file :https://youtu.be/YKvm0s

 

Source

user-image
Question added by kadrleyn kadr leyn , engineer , www.merkez-ihayat.com
Date Posted: 2017/08/08
Andrew Ryder
by Andrew Ryder , Developer , United Arab Bank

 

Declare the worksheet as a worksheet object.  Declare the ranges (source data, criteria, output) as range objects.

You can then use Autofilter or the more powerful Advanced Filter to achieve the output.  Using Advanced Filter in VBA is actually better than in Excel as the output range can be on a different worksheet to the source data. 

eg:

Sub FilterCells()    Dim wsSource As Worksheet    Dim wsTarget As Worksheet        Dim rgSourceData As Range    Dim rgCriteria As Range    Dim rgOutput As Range        Set wsSource = ActiveSheet    Set wsTarget = Worksheet.Add(after:=wsSource)        Set rgSourceData = wsSource.Range("A3:K300")    Set rgCriteria = wsSource.Range("F2")        Set rgOutput = wsTarget.Range("A1")        rgSourceData.AdvancedFilter _        Action:=xlFilterCopy, _        CriteriaRange:=rgCriteria, _        Copytorange:=rgOutputEnd Sub

Note: this assumes the text box linkedcell is F2.  If the objective is to view the filtered data rather than copy it to a new location, then the above works just as well with the Action as xlFilterInPlace and the CopytoRange is not needed.

Jayesh Prajapati
by Jayesh Prajapati , Financial Analyst - MEA , Weatherford

Range.Autofilter Field:=1, Criteria1:=

Suresh Thombare
by Suresh Thombare , Product Design Engineer , Honeywell Process Solutions, RMZ ECO WORLD

In Excel We have  a option Autofilter

By writting VBA Code We can filter: Try Ths

Sub Datafilter()

Range(“A1″).AutoFilter Field:=1, Criteria1:=”Jan” 

Jan is replace by your criteria

End Sub

abdelhafid beghdadi
by abdelhafid beghdadi , Mechanical Engineer / Maintenance Supervisor / Manager Quality Management , EPTP & SONATRACH

oui  on peu developer une application pour filtrer automatiqueemnt

Firas Shahadi
by Firas Shahadi , Training And Development Director , Muhayal Assir National Hospital

you can use the AutoFilter method of Range

Range().AutoFilter

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.