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:
50+ Project Management Templates Pack
Excel PowerPoint Word
Advanced Project Plan & Portfolio Template
Ultimate Project Management Template
20+ Excel Project Management Pack
20+ PowerPoint Project Management Pack
10+ MS Word Project Management Pack
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 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 – 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.
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.
|Excel VBA Reference||Project Management Reference|