如何在切片机的每个成员之间遍历Excel Pivot切片机,同时将一张纸的结果保存到另一张纸上?

时间:2018-09-27 16:59:52

标签: excel vba excel-vba

我试图遍历1个切片器,以获取所有我想从一个单元格捕获值并将其粘贴到另一张纸上的项目(同时还捕获切片器项目名称)。请帮忙,我知道我需要循环,但是什么也无法工作

Sub CtryFilter2()

Dim sC As slicerCache
Dim sI As slicerItem
Dim sIDummy As slicerItem
Dim i As Long
Dim l As Long

'application.ScreenUpdating=false

'Assign slicer to variable
Set sC = ActiveWorkbook.SlicerCaches("Slicer_CTRY_DESC")

'Initiate loop through each country in the slicer
sC.PivotTables(1).ManualUpdate = True
'sC.ClearManualFilter

With sC
For i = 1 To sC.SlicerCacheLevels.Count

    For Each sI In sC.SlicerCacheLevels(i).SlicerItems

    If i = 1 Then Sheets.Add.Name = sC.Name Else

        Sheets("Graph").Range("C2:R2").Copy
        Sheets(sC.Name).Range("b" & i).PasteSpecial xlPasteValues

    End
        'sC.ClearManualFilter

        'Create new tab and rename based on current selection
        'Sheets.Add.Name = sI.Value
        'Copy paste values from POS_DETAIL tab to the new tab
        Sheets("Graph").Range("C2:R2").Copy
        Sheets(sC.Name).Range("b" & i).PasteSpecial xlPasteValues
    Next sI

下一个我     结束于     '垃圾收集     设置sC =否 结束

0 个答案:

没有答案