How To Filter Data In Excel? Nowadays, excel files are loaded with numerous records. In such cases, it is very difficult to find an information quickly. Excel’s Filter will help us hide unwanted records and lets us view only necessary records on the worksheet.
Filter records through the GUI
Level of difficulty: LOW
Option 1: Excel’s Filter
Before using Excel’s filter, make sure that your data range has headers. The filter will be applied to each column and the header row will be used to identify the column name. Excel will not throw an error if the header row is missing. It will still continue to apply filter drop downs on the first row in your data range.
Follow the steps mentioned below to apply the filter to records on an Excel worksheet:
Step 1: On the Excel ribbon, select the tab “Data”. Under the group, “Sort & Filter”, click on “Filter”. Now each column in the header row will have a drop-down arrow. Please note, before clicking the option “Filter”, make sure that there are no blank rows in between records.
If there is a blank row, the filter will be applied only to records that are above the blank row and the rows below the blank row will be skipped from filtering
Step 2: If you want to include blank records, you must manually select the entire data range and then apply the Filter. If you do so, Excel will treat blank as a value and in the filter drop down, you could see blank as a filter criterion.Step 3: Excel automatically recognizes the data type of each column in your data range. Based on the data type, the filter type varies on each column. On a column that contains text, you would see Text filters, whereas on a column with numbers you would see Number filters. Similarly, on a column with dates, you would see Date filters0. In Ms Excel’s Date filter allows you to filter your data using 35 different options. The table below gives a detailed list of those options.The table below gives a detailed list of those options.
In Excel’s Number filter allows you to filter your data using 11 different options. The table below gives a detailed list of those options.
Excel’s Text filter allows you to filter your data using 7 different options. The table below gives a detailed list of those options.
The filter can be applied on a single column or multiple columns. As you the apply filter, you can see that the records that do not meet the filter criteria are hidden.
How To Filter Data In Excel & Why Excel shows Text filter for Columns containing dates
Sometime excel will show Text filters on columns that contain dates and this is because of the following reasons:
1) Users might have formatted dates and saved them in cells as text.
2) The cell into which date was entered has text format.
3) When the Excel sheet was generated, all the data entered was in text format.
We must convert those columns into correct datatype so that we can view and apply an appropriate filter over such columns. For changing dates which are in text format into a proper date format, you can use Excel’s Date Value function. You must pass the date in text format to this function and it will return a serial number.
Using the Date value function in an empty column, pass the first cell in the range as a parameter to the function and then using fill handle apply this to the entire range. Do not forget to switch the format to date on the new column.
If you are not comfortable with the manual conversion of dates in text format to actual date format, then use the query below.
As per this query, Column V contains the date in text format. This query first finds the last used row in Column V and then converts every record into date format. This macro does not require a new column as the converted data replaces the existing data. However,
If you using the manual method, you have to create a new column.
The script below will help you to convert text to numbers. This script multiplies the value in the cell by 1 and then converts the format of the cell to General.
Manage filtered records
Unlike Excel’s advanced filter that has an inbuilt option to copy filtered records to a new destination, the Filter option does not have options to manage filtered records. To copy filtered records to a new destination in the worksheet, select “Find & Select” from the tab Home on the Excel ribbon.
Then click on “Go to Special”. A form will pop up. Select “Visible cells only” and then click on Ok. Excel will now select visible records which you can easily copy and paste into new sheet using Ctrl+c and Ctrl+v.
Filter is not automatic
Consider you have applied the text filter on a column with the condition “Begins with ‘A’”. After the filter, the column will hold records that begins only with ‘A’. However, if you change any of the filtered records to begin with a letter other than ‘A’,
Excel will not automatically identify this and it will not hide this record since this record has not been passed to the filter criteria. You must manually reapply the filter. To do that, from the Excel ribbon, click on the Tab “Data”. Then from the group, “Sort & Filter”, click the option “Reapply”.
How To Filter Data In Excel Reapply filter using VBA
Using the option “Reapply” from the Excel ribbon is a manual task. Using a macro, we can automate it.
Step 1: Within your Excel workbook, activate the worksheet that has a filter applied to your data set.
Step 2: Right-click on the worksheet tab and from the list of the visible context menu, click “View Code”. This will open the Visual-basic editorStep 3: Paste this code into the VBA editor
Step 4: Save your workbook as macro-enabled Excel file.
Step 5: Now, for any change you make on the filtered record, Excel will automatically track the change and will reapply the filter.
Option 2: Advanced Filter
Step 1: Before using Excel’s advanced filter, you might have to set up your data range. Make sure that your data has column header and each header has a unique name. If names in your header are duplicated, Excel’s advanced filter will throw an error.
You should also ensure that there are no blank records in between your data. If there are blank records, delete them manually or send them to the last row by sorting records.
However, it would be very easy if the Criteria range is just above the data set. If your first record in your data set starts at row 1, then insert new rows at the top and push your data set below. Copy Column headers from your data set and paste it as Column headers to your filter criteria range.
Always ensure that Column headers of your data set and Column headers of the Criteria range are same. A mismatch in the column header will hide all records in your data set.
Step 3: We are now ready to apply the Advanced filter. After selecting any cell in your dataset, on your Excel ribbon, select the tab “Data”. From the group, “Sort & Filter”, click “Advanced”. This will bring up a user form. In the user form under Action, the option “Filter the list, in-place” will apply the filter on the active sheet.
You can then copy filtered records to a different sheet using the option “Copy to another location”. The three text boxes on this form will allow you to define the range of your data set, the range of the filter criteria, and the new destination to which your records should be copied after the filter is applied.
The option “Unique records only” will help you to remove duplicates from filtered records. After choosing your options, press “OK” on the form and your data will be filtered.
How To Filter Data In Excel Advanced filter is not automatic
The advanced filter will not recognize changes that you make to your data set or to the criteria change. After making changes, you must again click on the option “Advanced” from the Excel. This time, when the form opens, all your previous values will reappear. You must press “Ok” to reapply the filter.
Reapply advanced filter using VBA
Using VBA, we can automatically refresh the filter criteria.
Step 1: Within your Excel workbook, activate the worksheet that has an advanced filter applied on your data set.
Step 2: Right-click on the worksheet tab and from the list of the visible context menu, click “View Code”. This will open the Visual-basic editorStep 3: Paste this code into the VBA editor.
Do not miss to update placeholders <Data Range> and <Criteria Range> with actual values. Now for any change that you make to your data set or to your criteria range, the advanced filter will be reapplied.
Operators and wildcards in advanced filter
The table below lists operators and wildcards that can be used in the criteria range
In The wildcard * informs Excel that it can be any character and any number of characters. In the image below, text at A2 is a criterion for the auto filter on the data set below it. The value “*ani*” will filter the dataset and will show records that have “ani” in it.
The wildcard ? informs Excel that it can be any single character.
With the wildcard ~, you would be able to filter records that contain another wildcard. For example, if the text in a column contains the symbol “*”, which is a wildcard for advanced filter criteria, you can filter records by making the criteria look like this <text>~*<text>. Replace the placeholder <text> with appropriate values.
If ="=?????" is the criteria value, it filters dataset with columns values whose length does not exceed 5.
If ="=text" is the criteria value, it filters dataset with column values that match exactly with the criteria value.
How To Filter Data In Excel Create conditions in advanced filter
If you list multiple criteria in the same row, you create an ‘AND’ condition. According to the image below, the data set is filtered using two conditions.
Condition 1: The region should have the text “asia”. Any character and any number of character can be present before and after the text “asia”
Condition2: The population should be greater than 500,000Records that pass both these conditions will be visible on the sheet and records that do not pass both these conditions will be hidden.
If you list multiple criteria in a different row, you create an OR condition. According to the image below, records that have the text “asia” in the column “Region” or records that have a population greater than 500,000 passes the filter criteria and will be visible on the sheet.
Filter using VBA
You can use a macro to filter large data sets. Here are some macros that you can paste into a new module and invoke to filter records. Replace placeholders <Data Range> and <Criteria Value> with appropriate values.
This script applies text filter to the field1 in the data set. Records that begin with the criteria value pass the filter criteria.
This script applies text filter to the field1 in the data set. Records that contain the criteria value pass the filter criteria.
This script applies text filter to the field1 in the data set. Records that do not contain the criteria value pass the filter criteria.
This script applies text filter to the field1 in the data set. Records that end with the criteria value pass the filter criteria.
If you are using VBA to filter records in a worksheet, it is very important to identify if the sheet already has a filter applied. Copy this script into your workbook and run the script. This will identify if the active sheet has a filter on it.
This script will remove filters applied on a sheet and will display all records on it.