REAL-TIME

VBA Projects

Full Access with Source Code

  • Designed and Developed by PNRao

  • Full Access with VBA Source Code

  • Well Commented Codes Lines

  • Creative and Professional Design

120+ PROFESSIONAL

Project Management Templates

120+ PM Templates Includes:
  • 50+ Excel Templates

  • 50+ PowerPoint Templates

  • 25+ Word Templates

Effortlessly Manage Your Projects

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

Share Post

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

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.

 

Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Project Management Templates

All-in-One Pack
120+ Project Management Templates

Essential Pack
50+ PM Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project
Management Template
Ultimate Resource
Management Template
Project Portfolio
Management Templates
Categories: VBA FilterLast Updated: March 18, 2023

5 Comments

  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.

  2. Sunil December 8, 2019 at 12:50 PM - Reply

    Hi ,

    This is really helpful. Thanks for the code.

    However, I am facing a challenge of filtering a column based on each value in that column; some of them may not be known.

    For example, in one of the columns, I have names and want to apply filter on it. However, I know few names that can be applied in filters. But there can be couple of more names which I am not aware. Hence I need to apply filters for each available value in that column. Is there a way to do it?

  3. Arun December 30, 2019 at 4:42 PM - Reply

    How to get cell value after applying the filter

  4. Bobby January 30, 2020 at 7:01 PM - Reply

    HI,

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

    In the above line, the range is known. Please let me know how to make it dynamic with unknown range.

    Thank you!!
    Bobby

  5. dakota September 15, 2020 at 7:00 PM - Reply

    maybe this helps when the range is unknown:

    Sub Names()
    Dim sh As Worksheet

    Set sh = ThisWorkbook.Worksheets(“sheet1”)
    sh.UsedRange.Select
    With Selection
    .AutoFilter
    End With

    End Sub

Leave A Comment