mosesthetank
New Member
- Joined
- Nov 30, 2013
- Messages
- 16
The below macro creates a filter based on the value in A2. I want it to execute every time A2 changes. A2 is a cell reference to another sheet (pivot table). The only way the filter currently updates is if I press Enter in A2. I have tried writing this several different ways but they all require pressing Enter.
Can the below code be be written so as to refresh the filter as A2 changes without using Enter?
Can the below code be be written so as to refresh the filter as A2 changes without using Enter?
Code:
[FONT=Arial]Private Sub Worksheet_Change(ByVal Target As Range)[/FONT][FONT=Arial]Dim KeyCells As Range[/FONT]
[FONT=Arial]Set KeyCells = Range("A2")[/FONT]
[FONT=Arial]
[/FONT]
[FONT=Arial]If Not Application.Intersect(<wbr>KeyCells, Range(Target.Address)) _[/FONT]
[FONT=Arial] Is Nothing Then[/FONT]
[FONT=Arial]
[/FONT]
[FONT=Arial]Set Target = Target.Cells(1, 1)[/FONT]
[FONT=Arial]If Not Intersect(Target, Range("A2")) Is Nothing Then[/FONT]
[FONT=Arial]Range("B2").CurrentRegion.<wbr>AutoFilter field:=2, Criteria1:=Target.Value[/FONT]
[FONT=Arial]End If[/FONT]
[FONT=Arial]
[/FONT]
[FONT=Arial]
[/FONT]
[FONT=Arial]End If[/FONT]
[FONT=Arial]
[/FONT]
[FONT=Arial]End Sub[/FONT]