Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par kadrleyn kadr leyn , engineer , www.merkez-ihayat.com
Date de publication: 2017/08/08
Andrew Ryder
par 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
par Jayesh Prajapati , Financial Analyst - MEA , Weatherford

Range.Autofilter Field:=1, Criteria1:=

Suresh Thombare
par 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
par abdelhafid beghdadi , Mechanical Engineer / Maintenance Supervisor / Manager Quality Management , EPTP & SONATRACH

oui  on peu developer une application pour filtrer automatiqueemnt

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

you can use the AutoFilter method of Range

Range().AutoFilter

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?