Dynamic Cell-Based Filter

Automatically filter table data based on values entered in specific cells with real-time updates and multiple filter criteria.

350 views

Perfect For:

  • Interactive dashboards
  • User-controlled filtering
  • Search interfaces
  • Dynamic reports
  • Data exploration tools

PRO Template

Sign up for free to unlock the complete VBA code and access all templates

VBA Code (Preview)
Sign up to copy
' Dynamic Cell-Based Filter
' Place this code in the Worksheet module where your data table exists
' Assumes data table starts at row 6, filter cells are C2 and H2

Private Sub Worksheet_Change(ByVal Target As Range)
    ' Trigger filter when C2 or H2 changes
    On Error GoTo ErrorHandler

    Dim filterCell1 As Range
    Dim filterCell2 As Range
    Set filterCell1 = Me.Range("C2")
    Set filterCell2 = Me.Range("H2")

    ' Check if changed cell is one of the filter cells
    If Not Intersect(Target, filterCell1) Is Nothing Or _
       Not Intersect(Target, filterCell2) Is Nothing Then

        Application.EnableEvents = False
        Call ApplyDynamicFilter
        Application.EnableEvents = True
    End If

    Exit Sub

ErrorHandler:
    Application.EnableEvents = True
    MsgBox "Error applying filter: " & Err.Description, vbCritical
End Sub

Sub ApplyDynamicFilter()
    ' Apply filters based on cell values
    On Error GoTo ErrorHandler

    Dim ws As Worksheet
    Set ws = Me

    Dim filterValue1 As String
    Dim filterValue2 As String

    filterValue1 = Trim(ws.Range("C2").Value)
    filterValue2 = Trim(ws.Range("H2").Value)

    ' Get the data table (assumes it starts at row 6)
    Dim dataTable As ListObject
    On Error Resume Next
    Set dataTable = ws.ListObjects(1)
    On Error GoTo ErrorHandler

    ' If table doesn't exist, create it
    If dataTable Is Nothing Then
        Dim lastRow As Long
        Dim lastCol As Long
        lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row

' ... 125 more lines hidden ...
'
' Sign up for free to view the complete code
' Visit: vbacode.io
Access all 45 templates
10 free AI generations/month
No credit card required

Related Topics

filter dynamic cell-based real-time interactive

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

3 free generations/month — unlimited with Pro

Related Templates

More VBA templates in the same category

Intermediate

Create Sheet Per Unique Value

Automatically create separate worksheets for each unique value in a column. Perfect for splitting...

View Template