我目前有一个宏来自动过滤我的数据。当单元格更改时,我无法让它自动运行。我希望宏在单元格中的值发生变化时运行。将不胜感激任何帮助。我想知道问题是否出在我将代码放入哪个工作表中。
我的代码如下。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed. In this case,
' Cell B2 will be changed when a value is selected on
' another worksheet.
Set KeyCells = Range("B1:B2")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Perform advanced filter on data
' Place your code here.
Range("B4:H976").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("SalesByLocation!Criteria"), Unique:=False
End If
End Sub