【问题标题】:how can i see how many items are selected in a pivotable slicer via vba我如何查看通过 vba 在数据透视表切片器中选择了多少项目
【发布时间】:2016-10-07 21:51:24
【问题描述】:

我在 microsoft Excel 上有一个带有切片器的数据透视表,我想制作一个宏,如果在切片器上选择了多个项目,则会发生某些事情。

有人可以帮我吗?

【问题讨论】:

    标签: excel vba count pivot-table slicers


    【解决方案1】:

    这是我编写的一个函数,用于获取切片器中的选择。它将返回一个逗号分隔的选定切片器项目的字符串。

    如果您愿意,您可以调整它以仅返回一些选定的项目。虽然我个人认为知道选择了哪些项目更重要。

    'This function takes one parameter
    'This is the Formula name for the slicer
    'you can find this name by right clicking on a slicer
    'and choosing Slicer Settings...
    Public Function getSlicerChoices(SlicerName As String) As String
        Dim slicerval       As SlicerCache
        Dim sItm            As SlicerItem
    
        Set slicerval = ThisWorkbook.SlicerCaches(SlicerName)
    
        For Each sItm In slicerval.VisibleSlicerItems
            If sItm.Selected Then
                If sItm.Name <> "(blank)" Then
                    If getSlicerChoices = "" Then
                        getSlicerChoices = "'" & Replace(Trim(sItm.Name), "'", "''") & "'"
                    Else
                        getSlicerChoices = "'" & Replace(Trim(sItm.Name), "'", "''") & "'," & getSlicerChoices
                    End If
                End If
            End If
        Next sItm
    
        'Take last comma off the string
        If Right(getSlicerChoices, 1) = "," Then
            getSlicerChoices = Left(getSlicerChoices, Len(getSlicerChoices) - 1)
        End If
    
        getSlicerChoices = Replace(getSlicerChoices, "(blank)", "")
        Set slicerval = Nothing
    
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多