select切片机中的项目列表

我正试图帮助书店的圣诞销售! 我使用连接到OLAP Cube的数据透视表,提供了大量的产品参考,并提供了有价值的信息,例如上周的销售情况,库存水平等。

我只想显示当前商业行为(约400本书)的图书数据(销售和库存水平),以检查库存水平是否足够。

我有一个带有ISBN号码的切片机,上面有超过一百万个字幕,我想用VBA操纵这个切片,只显示我想要的书。

我想要显示的ISBN列表在表“目录EOY”,第3列。我试图build立一个数组右边的切片器名称,用于VisibleSlicerItemsList语句,但我得到一个消息“对象需要”在那一行(最后一行)。 在我的例子中,我把书的清单限制在前50项。

任何想法如何我可以解决这个问题?

Sub ShowProductList() Dim ProductList(0 To 50) As Variant Dim i Dim Sc As SlicerCache Dim sL As SlicerCacheLevel Set Sc = ActiveWorkbook.SlicerCaches("Slicer_ISBN") Set sL = Sc.SlicerCacheLevels(1) For i = 2 To 52 ProductList(i - 2) = Chr(34) & "[DIM Artikel].[ISBN].&[" & _ Worksheets("Catalogue EOY").Cells(i, 3).Value & "]" & Chr(34) Next i sL.VisibleSlicerItemsList = ProductList End Sub 

 Sub f() Dim piv As PivotItem, pivf As PivotField, pivt As PivotTable, ProductList() As Variant, filterrng As Range, rng As Range 'the range where your background data is Set filterrng = Worksheets("filter_criteria").Range("C2:C52") 'the range where your product list is ReDim ProductList(filterrng.Cells.Count - 1) For Each rng In filterrng ProductList(i) = rng.Value2 i = i + 1 Next rng Set pivt = Sheets("piv").PivotTables("PivotTable1") 'your pivottable, define it properly Set pivf = pivt.PivotFields("ISBN") 'the pivot field On Error Resume Next For Each pvi In pivf.PivotItems pvi.Visible = False pvi.Visible = Application.Match(pvi.Name, ProductList, False) > -1 'if it's in the range, then make it visible, otherwise hide it Next pvi End Sub 

不是你想要的答案,而是你需要的答案。

您需要遍历每个SlicerItem,并根据您的列表对其进行testing,以select是否select它,以下是方法:

 Sub ShowProductList() With Application .EnableEvents = False 'stop executing this code until we are done .DisplayAlerts = False .ScreenUpdating = False '.Calculation = xlCalculationManual End With Dim ProductList(0 To 50) As Variant Dim i As Long Dim Sc As SlicerCache Dim sI As SlicerItem Dim sL As SlicerCacheLevel Dim inLisT As Boolean Set Sc = ActiveWorkbook.SlicerCaches("Slicer_ISBN") Set sL = Sc.SlicerCacheLevels(1) For i = 2 To 52 ProductList(i - 2) = Chr(34) & "[DIM Artikel].[ISBN].&[" & _ Worksheets("Catalogue EOY").Cells(i, 3).Value & "]" & Chr(34) Next i Sc.ClearManualFilter For Each sI In Sc.SlicerItems inLisT = False For i = LBound(ProductList) To UBound(ProductList) If sI.Name <> ProductList(i) Then Else inLisT = False Exit For End If Next i If inLisT Then sI.Selected = True Else sI.Selected = False End If Next sI With Application .EnableEvents = True 'stop executing this code until we are done .DisplayAlerts = True .ScreenUpdating = True '.Calculation = xlCalculationAutomatic End With End Sub