樞紐分析表的篩選-自動全選
詢問一下 在sheet裡面 已有一個既定的樞紐分析表也在樞紐分析表選項勾選了檔案開啟時自動更新,但我都是使用內建資料重新整理就不需重新開啟檔案
目前發現的是 每次重新整理 裡面的資料有些預設是不會顯示的 需要到樞紐分析內點擊全選才會跑出
想說有沒有語法可以直接ALL Visible True這樣!!
我利用巨集錄製到下面的語法,但並不是每次內容都一樣
With ActiveSheet.PivotTables("樞紐分析表6").PivotFields("風險名稱")
.PivotItems("1").Visible = True
.PivotItems("a").Visible = True
.PivotItems("c)").Visible = True
.PivotItems("N").Visible = True
.PivotItems("5").Visible = True
.PivotItems("6").Visible = True
.PivotItems("g").Visible = True
End With
可能下次 裡面的值會變成 .PivotItems("P").Visible = True 之類的~ 這樣語法就沒辦法寫死
使用 .PivotItems(*).Visible = True 或 .PivotItems("*").Visible = True 皆無法正常執行 [code]
Dim PivotItem As PivotItem
For Each PivotItem In .PivotTables("樞紐分析表6").PivotFields("風險名稱").PivotItems
PivotItem.Visible = True
Next PivotItem
[/code] [b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=82126&ptid=15117]2#[/url] [i]Joforn[/i] [/b]
不好意思 他指出 .PivotTables 不正確的引用耶@@ [Range變數]沒有做動態處理
offset(,,,,)寫在定義名稱裡頭
//作包裝,樞紐分析表 再引用,用不著vba 我剛剛正好需要Joforn大大提供的方法
試著將.PivotTables("樞紐分析表6")改為 [color=Red][b]ActiveSheet[/b][/color].PivotTables("樞紐分析表6")
就可以了使用了 我使用了上述的語法,在上個月(四月)的檔案使用沒有問題
現在五月份,我沿用原本檔案,直接複製改檔名,內容更新成五月的資料
執行VBA,就出現錯誤訊息:執行階段錯誤 1004,無法設定種類PivotItem的Visible屬性
PivotItem.Visible = True <--這行出錯
我在偵錯模式下,鼠標在PivotItem字串上時,顯示PivotItem = "4/1/2022"
請問會是什麼問題?
-----------------------------------------------------------
Dim PivotItem As PivotItem
For Each PivotItem In ActiveSheet.PivotTables("樞紐分析表6").PivotFields("風險名稱").PivotItems
PivotItem.Visible = True
Next PivotItem
頁:
[1]