How to filter data just by clicking cell content in Excel?
Normally, in Excel, you can apply the Filter function to filter data by your need. But, in this article, I will talk about how to filter data just by clicking a cell value. Take the following data as example, when I double click the cell A2, all corresponding records based on this clicked value will be filtered at once as below screenshot shown.
- Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
- More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
- Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
- Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
- Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
- Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
- More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.
Here, I will provide a VBA code for you to filter data by clicking a cell, please do as follows:
1. First, give your data a range name, please enter a range name into the Name Box, and press Enter key, see screenshot:
2. Right click the sheet tab which you want to filter by clicking cell, and then choose View Code from the context menu, and in the opened Microsoft Visual Basic for Applications window, copy and paste the following code into the blank Module:
VBA code: Filter data by clicking cell value:
Option Explicit Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) 'Updateby Extendoffice 20161123 Dim rgTable As Range Dim rgData As Range Dim xColumn As Integer On Error Resume Next Application.ScreenUpdating = False Set rgTable = Range("mydata") With rgTable Set rgData = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) If Not Application.Intersect(ActiveCell, rgData.Cells) Is Nothing Then xColumn = ActiveCell.Column - .Column + 1 If ActiveSheet.AutoFilterMode = False Then .AutoFilter End If If ActiveSheet.AutoFilter.Filters(xColumn).On = True Then .AutoFilter Field:=xColumn Else .AutoFilter Field:=xColumn, Criteria1:=ActiveCell.Value End If End If End With Set rgData = Nothing Set rgTable = Nothing Application.ScreenUpdating = True End Sub
Note: In the above code, mydata is the range name you have created for your data range, please change it to your need.
3. Then save and close the code window, now, when you double click any cell of the data range that you want to filter out, its corresponding records will be filtered as following screenshot shown:
More related articles:
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 1 years agoHi, I have a summary sheet, that calculates how many lines on the main sheet that are within a certain date range. I want to be able to double click on a certain date range and it then filter out the data on the main sheet to the date range I double clicked on. What code would I need for this please
- To post as a guest, your comment is unpublished.· 1 years agoBuenas tardes
Excelente aportación ... lástima que no funcione con un archivo protegido ... qué podría cambiarle para que si funcione?
- To post as a guest, your comment is unpublished.· 2 years agoMuito bom!
Entretanto, só funciona em um intervalo.
Eu queria aplicá-lo em uma Tabela, é possível? Ficaria muito agradecido se sim!!