![](/img/trans.png)
[英]Excel VBA: Checking if the values in a table exist in a different range [like an error check function], plus locating unmatched item
[英]Choose function values unmatched in pivot table
我是VBA的新手,我正在編寫此宏以從數據透視表中獲取值並將其存儲在數據透視表附近的單元格中。 問題是當在透視表中找不到用select函數編寫的任何值時,它顯示了應用程序定義的錯誤或對象定義的錯誤,我無法從select中刪除字段,因為將來將來更新透視表時該值可以存在。
在這方面的任何幫助將不勝感激。
For i = 1 To 8
Set rng = Intersect(pt.PivotFields("Category").PivotItems("Technical").DataRange.EntireRow, _
pt.PivotFields("Office").PivotItems(Choose(i, "Mum", "blore", "chen", "delhi", "chandigarh", "hyd", "pune", "noida")) _
.DataRange.EntireRow, pt.PivotFields("Total").DataRange)
If rng Is Nothing Then
Else
Worksheets(6).Range(Choose(i, "AF29", "AF23", "AF24", "AF25", "AF30", "AF26", "AF27", "AF28")).value = CInt(WorksheetFunction.Percentile(rng, 0.95))
End If
Next i
使用錯誤處理程序來處理該問題。
For i = 1 To 8
On Error Resume Next
Set Rng = Intersect(pt.PivotFields("Category").PivotItems("Technical").DataRange.EntireRow, _
pt.PivotFields("Office").PivotItems(Choose(i, "Mum", "blore", "chen", "delhi", "chandigarh", "hyd", "pune", "noida")) _
.DataRange.EntireRow, pt.PivotFields("Total").DataRange)
On Error GoTo 0
If Not Rng Is Nothing Then
Worksheets(6).Range(Choose(i, "AF29", "AF23", "AF24", "AF25", "AF30", "AF26", "AF27", "AF28")).Value = CInt(WorksheetFunction.Percentile(Rng, 0.95))
End If
Next i
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.