2016-07-25 2 views
0

아래 코드가 있습니다. Looping through report filters to change visibility doesn't work 솔루션이 작동하는 것으로 표시되어 있습니다. 내 필요에 따라 수정 한 후에는 다음과 같이이다 :'1004'오류 : PivotItem 클래스의 Visible 속성을 설정할 수 없습니다.

With pt.PivotFields(6) 
    .ClearAllFilters 
    If .PivotItems.Count > 0 Then 

     'goofy but necessary 
     Set firstPi = .PivotItems(1) 

     For Each pi In .PivotItems 

      If firstPi.Visible = False Then 
       firstPi.Visible = True 
      End If 

      'Don't loop through firstPi 
      If pi.Value <> firstPi.Value Then 
       itemValue = pt.GetPivotData("[Measures].[Nr of Cancelled]", "[Characteristics].[Reason]", pi.Name).Value 

       rw = rw + 1 
       nwSheet.Cells(rw, 1).Value = pi.Name 
       nwSheet.Cells(rw, 2).Value = pi.Visible 
       If itemValue < 2000 Then 
        If pi.Visible = True Then 
         pi.Visible = False 'Error here 
        End If 
       Else 
        MsgBox pi.Value 
        If pi.Visible = False Then 
         pi.Visible = True 'Error here 
        End If 
       End If 
      End If 
     Next 

       'Finally perform the check on the first pivot item 
       If firstPi > 2000 Then 
        firstPi.Visible = True 
       Else 
        firstPi.Visible = False 
       End If 
      End If 
    End With 

나는 모든 코드가 잘 작동하고 내가 오류만을 라인에 직면하고있어 pi.Visible = True 또는 pi.Visible = False

내가 어디 모르겠어요 볼 나는 코드가 작동하지 않도록 잘못했다.

나는 soltuion를 위해 인터넷을 검색했다

,이 링크를 통해 온 : MS는 피벗 테이블 필드에서 연속 항목을 숨길 수 있음을 언급 https://support.microsoft.com/en-us/kb/114822가. 내 테이블의 항목이 인접하지 않음을 의미합니까? 누구든지 나를 도울 수 있습니까? 나는 여기에서 길을 잃는다.

+0

*** 테이블에있는 항목이 *** 연속되어 있습니까? 나는 SO에있는 누군가가 그 질문에 답할 수 있을지 의심 스럽다. – Comintern

+0

연속 여부를 어떻게 확인할 수 있습니까? 나는 이것을 모른다. – Pramod

+0

엑셀 파일을 볼 수 있니? 그렇다면 무료 파일 공유 사이트에 업로드하여 여기에 링크를 공유하십시오. 또한 기밀 데이터가있는 경우 더미 데이터로 대체하십시오. –

답변

1

오류에 대한 해결책을 찾지 못했습니다. 그러나 나는 그 일을 성취 할 또 다른 방법을 찾았다. 내가 HiddenItemsList 또는 VisibleItemsList 중 하나를 호출 할 수 있도록 내가 볼 수 있도록 모든 숨길 항목 및 항목을 저장하는 배열을 사용 :

For Each pvtitem In pt.PivotFields(6).PivotItems 
     On Error GoTo skipreason 
     itemValue = pt.GetPivotData("[Measures].[Cancelled]", "[Characteristics].[Reason]", pvtitem.Name).Value 
     If itemValue < 2000 Then 
      hiddenReasons(hiddenCount) = pvtitem.Name 
      hiddenCount = hiddenCount + 1 
     Else 
      visibleReasons(visibleCount) = pvtitem.Name 
      visibleCount = visibleCount + 1 
     End If 

Sheets("Cancels").PivotTables("Cancels").PivotFields(_ 
    "[Characteristics].[Reason].[Reason]" _ 
    ).VisibleItemsList = Array(visibleReasons()) 
+0

++ 다행 니 자신이 해결해 줬어 :) –

관련 문제