VBA Filter Column

Home/VBA/VBA Filter/VBA Filter Column

VBA filter column macro helps filter the data in a specific Column. Let us see different example macros to filter the records or rows based on items in one column. Example Data to Explain the VBA Filter:
VBA Filter Column

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

BROWSE ALL TEMPLATES

50+ Project Management Templates Pack
Excel PowerPoint Word

VIEW DETAILS

Advanced Project Plan & Portfolio Template
Excel Template

VIEW DETAILS

Ultimate Project Management Template
Excel Template

VIEW DETAILS

20+ Excel Project Management Pack
Excel Templates

VIEW DETAILS

20+ PowerPoint Project Management Pack
PowerPoint Templates

VIEW DETAILS

10+ MS Word Project Management Pack
Word Templates

VIEW DETAILS


Here is the Example data to illustrate the macro on VBA Filter Column. This Example Data sheet contains 100 records with sample data items. We have created employee records with columns: Serial Number, Name, Country, Department, DOJ and Salary to explain this topic.

VBA Filter Column – Excel Data

VBA to Filter data in a specific Column:

Let us see an Example VBA macro to filter the records in a worksheet. This Example shows how to filter Data based on an item in Column C using Excel VBA.

We have 100 rows in the data sheet and Country details in Column C. Let us filter the data to show only records from county US. i.e; We need to apply the filter on Column C and set the criteria as US.

Here is the VBA Code created with Macro Recorder:

Sub Macro1()

' Macro1 Macro 

Columns("A:F").Select

Selection.AutoFilter

ActiveSheet.Range("$A$1:$F$101").AutoFilter Field:=3, Criteria1:="US"

End Sub

Let us Clean the code to have the final VBA code to filter the data in Column.

Sub sbAT_VBAMacroToFilterColumn()

' VBA Code to filter records of Columns A to F based on the data item in Column C

ActiveSheet.Range("$A$1:$F$101").AutoFilter Field:=3, Criteria1:="US"

End Sub

 

We have removed all unnecessary code and left with the required code for filtering the data.
Let us see the code in-depth:

We are using the AutoFilter method of the range. In the above code, we have created a macro to apply the filter on Range A1:F101 of the active worksheet. And applied the filter on Column 3 and set the criteria as US.

This Example macro will filter the records in Range A1:F101 and show all records with US in Column 3 , i.e; in Column C. Here is the final out put of the VBA Filter Column Macro:

VBA Filter Column – Filtered Data

VBA Filter Column – Download the Example File

Here is the Example file with sample data. You can download the Excel VBA Macro file and Explore to see the VBA code to filter column data.

VBA Filter Column – Example Macro File

 

Executing the Macro: VBA Filter Column:

  • Open the Example File
  • Go to Data sheet
  • Open VBA Editor (Press Alt+F11 to open it)
  • And Run the Macro by pressing F5 Key.

Now you can see the filtered records in Active sheet.

 

LIMITED TIME OFFER - Get it Now!
Advanced Project Plan Excel Template

 
Related Resource External VBA Reference
By |June 27th, 2018|VBA Filter|1 Comment

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

One Comment

  1. Jo June 28, 2018 at 6:02 PM - Reply

    Thanks for the VBA CODE provided for filtering the data based on an item in a specified Column. It is really helpful.

    Thanks a lot.

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.