Simple VBA Autofilter

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
Hi , I have the folowing simple code

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
With Worksheets("PutawayQ")
.Select
.Range("A1").AutoFilter Field:=1, Criteria1:=Target.Value
End With
End Sub

At present when I click any cell in the active sheet it filters by that value.
How can I make it will only work when a cell in Collumn A is sellected ,
I am guessing that it is something to do with the Range("A1").
I have tried various things ("A") , ("A1:A1000) ect but without any luck
Can anybody help
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 then Exit Sub
    Cancel = True
    With Worksheets("PutawayQ")
        .Select
        .Range("A1").AutoFilter Field:=1, Criteria1:=Target.Value
    End With
 End Sub
 
Upvote 0
There are different ways - for example:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 then
Cancel = True
With Worksheets("PutawayQ")
.Select
.Range("A1").AutoFilter Field:=1, Criteria1:=Target.Value
End With
End if
End Sub

or:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If not intersect(Target, Range("A:A")) Is nothing then
Cancel = True
With Worksheets("PutawayQ")
.Select
.Range("A1").AutoFilter Field:=1, Criteria1:=Target.Value
End With
end if
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top