Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA循环遍历数据透视项_Vba_Excel_Pivot - Fatal编程技术网

Excel VBA循环遍历数据透视项

Excel VBA循环遍历数据透视项,vba,excel,pivot,Vba,Excel,Pivot,我想循环查看我的透视项并检查它们是否存在于另一个表中,请参见我的示例屏幕截图: 因此,我想循环查看所有颜色,检查它们是否存在于另一张表中(例如,在另一张表中或其他表格中): 有没有办法做到这一点,这样会出现一个消息框,说明列表中没有紫色 非常感谢你的帮助 您可以使用以下内容: Sub ListMissingItems() Dim pt As PivotTable Dim pf As PivotField Dim pi As PivotItem Dim rng

我想循环查看我的透视项并检查它们是否存在于另一个表中,请参见我的示例屏幕截图:

因此,我想循环查看所有颜色,检查它们是否存在于另一张表中(例如,在另一张表中或其他表格中):

有没有办法做到这一点,这样会出现一个消息框,说明列表中没有紫色


非常感谢你的帮助

您可以使用以下内容:

Sub ListMissingItems()

    Dim pt As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem
    Dim rngList As Range
    Dim strMsg As String

    ' change sheet and range
    Set rngList = Worksheets("List").Range("A1:A10")

    Set pt = ActiveSheet.PivotTables(1)
    ' change field as needed
    Set pf = pt.PivotFields("Colour")

    For Each pi In pf.PivotItems
        If IsError(Application.Match(pi.Caption, rngList, 0)) Then strMsg = strMsg & vbLf & pi.Caption
    Next pi

    If Len(strMsg) > 0 Then MsgBox "The following items were not found in the list:" & strMsg
End Sub

很好用!非常感谢你!