This VBA macro filters a range on a worksheet by the value of the cell double clicked. It gets the last row of a range on another sheet, sets an autofilter on that range filtering the first column by the double clicked cell's value, and selects the first cell of the filtered range.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
38 views
Auto Filter
This VBA macro filters a range on a worksheet by the value of the cell double clicked. It gets the last row of a range on another sheet, sets an autofilter on that range filtering the first column by the double clicked cell's value, and selects the first cell of the filtered range.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 1 Then Exit Sub
Dim last As Long last = Sheet2.Cells(Rows.Count, "B").End(xlUp).Row Sheet2.Range("A1:Y" & last).AutoFilter Sheet2.Range("A1:Y" & last).AutoFilter Field:=1, Criteria1:=Target.Value
Cancel = True Application.Goto Sheet2.Range("B1") End Sub
(Last update file on 09-02-2022)
----------------------------------------------------------------------------------- ------ 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 .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