我正在尝试将数组传递给数据透视表字段,但这样做会导致运行时错误:1004错误“应用程序定义或对象定义错误”。下面是我在VBA中编写的代码:
Sub ARRAYER()
Dim i As Double
Dim ALM(8) As String
Sheet15.PivotTables("significance_pivot2").PivotFields("Pagename"). _
ClearAllFilters
For i = 1 To 8
ALM(i) = CStr(Sheet4.Range("F" + CStr(i + 2) + "").Text)
Next
For i = 1 To 8
Sheet4.Range("AA" & i).Value = ALM(i)
Next i
Sheet15.PivotTables("significance_pivot2").PivotFields("Pagename").VisibleItemsList = Array(ALM)-- It trows an error here!!!
End Sub
答案 0 :(得分:0)
也许尝试这样的替代方案:
Sub ARRAYER()
Dim i As Double
Dim ALM() As String ' dimensioned automatically by VBA on assignment from Range
Sheet15.PivotTables("significance_pivot2").PivotFields("Pagename"). _
ClearAllFilters
ALM = CStr(Sheet4.Range("F3:F11".value)
' maybe just copy the source data directly?
range("F3:F11").copy destination:= range("AA3")
Sheet15.PivotTables("significance_pivot2").PivotFields("Pagename").VisibleItemsList = Array(ALM())-- Changed to add brackets
End Sub