Vba 多个选择在一张工作表上更改检查

Vba 多个选择在一张工作表上更改检查,vba,selectionchanged,Vba,Selectionchanged,正在查看为多个单元格值创建SelectionChange。我将此代码用于单个选择更改: Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'This line stops the worksheet updating on every change, it only updates when cell H6 or H7 is touched If Intersect(Target, Range("O1"

正在查看为多个单元格值创建SelectionChange。我将此代码用于单个选择更改:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


'This line stops the worksheet updating on every change, it only updates when cell H6 or H7 is touched
If Intersect(Target, Range("O1")) Is Nothing Then Exit Sub
 
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
 
'Here you amend to suit your data
Set pt = Worksheets("Pivot Tables").PivotTables("PivotTable3")
Set Field = pt.PivotFields("OH Bucket")
NewCat = Worksheets("Pivot Tables").Range("O1").Value
 
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
 
End Sub
但我还需要检查范围(“C1”)是否改变,更新数据透视表1


任何帮助都将不胜感激。

您的代码将响应过程所在代码模块的工作表上O1(而不是您的备注所称的H6:H7)的更改。在数据透视表中捕获更改事件是一个完全不同的问题。坦白地说,如果你想在这里得到真正的帮助,你必须先看看你问题的细节。