Note: The other languages of the website are Google-translated. Back to English
Log in  \/ 
Register  \/ 


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.

doc filter by click 1

Filter data just by clicking a cell value with VBA code

arrow blue right bubble Filter data just by clicking a cell value with VBA code

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:

doc filter by click 2

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
    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
            End If
            If ActiveSheet.AutoFilter.Filters(xColumn).On = True Then
                .AutoFilter Field:=xColumn
                .AutoFilter Field:=xColumn, Criteria1:=ActiveCell.Value
            End If
        End If
    End With
    Set rgData = Nothing
    Set rgTable = Nothing
    Application.ScreenUpdating = True
End Sub

doc filter by click 3

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:

doc filter by click 4

More related articles:

How to change cell value by clicking on the cell?

How to sort column data by clicking on header in Excel?

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished. · 2 years ago
    Hi, 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.
    Daniel · 2 years ago
    Buenas 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.
    Heitor · 3 years ago
    Muito bom!
    Entretanto, só funciona em um intervalo.
    Eu queria aplicá-lo em uma Tabela, é possível? Ficaria muito agradecido se sim!!