0

我无法找到一种方法来捕获特定工作表中特定数据透视表中的任何更改。

枢轴是“pivottable6” 工作表是“APAC”

我已将此代码放在 APAC 工作表模块中:

Private Sub Worksheet_PivotTableChange(ByVal Target As Excel.PivotTable6)

With Target
 MsgBox "You performed an operation in the following PivotTable: " & .Name & " on " & Sh.Name
End With

End Sub

但我不断收到错误消息。关于如何解决它的任何想法?


Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Target, Target As PivotTable)

If Intersect(Target, ActiveSheet.PivotTables(1)) Is Nothing Then Exit Sub

MsgBox ("cat")

End If

End Sub

这仍然出现 USER TYPE NOT DEFINED ERROR

4

3 回答 3

0

在回答您的其他问题时,您需要将 IF 语句更改为以下内容:

Private Sub Workbook_SheetPivotTableChangeSync(ByVal Sh As Target, Target As PivotTable)

  If Intersect(Target, ActiveSheet.PivotTables(1)) Is Nothing Then 
     Exit Sub
  Else
    MsgBox ("cat")
  End If

 End Sub
于 2013-05-16T12:17:39.400 回答
0

您的代码使用了 Sh.Name,但未定义 Sh。改用 Me.Name。

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    With Target
       MsgBox "You performed an operation in the following PivotTable: " & .Name & " on " & Me.Name
    End With

End Sub
于 2013-05-16T10:14:29.880 回答
0

您想在工作表中的数据更改时刷新数据透视表吗?如果是,请尝试以下代码:

请将此代码放在具有枢轴的工作表上。

Private Sub Worksheet_Calculate()

    Sheets("APAC").PivotTables("pivottable6").RefreshTable

End Sub


Private Sub Worksheet_Change(ByVal Target As Range)

    On Error Resume Next

    Application.EnableEvents = False


    With Target
        MsgBox "You performed an operation in the following PivotTable: " & .Address & " on """ & Target.Parent.Name & """Sheet"
    End With


    Application.EnableEvents = True

End Sub
于 2013-05-16T09:25:57.183 回答