Reputation: 1
I tested the code with a small amount of product codes and it works but when I enter a large amount of product codes I get the
Run-time error '1004'
The item could not be found in the OLAP Cube.
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Product].[Source Product Number].[Source Product Number]").VisibleItemsList _
= ProductCodes
I imagine this means product codes in my list do not exist in the data base and throws this error. I aware of the on error resume next but the error happens at this point and I dont see how I can place that in the VisibleItemsList:
Sub OLAPfilterLIST()
'Set references up-front
Dim wksData1 As Worksheet
Dim wksData2 As Worksheet
Set wksData1 = ActiveWorkbook.Worksheets(1)
Set wksData2 = ActiveWorkbook.Worksheets(2)
Dim LastRow As Long
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Dim i As Long
i = 1
ReDim ProductCodes(1 To LastRow) As String
Dim A As Range
For Each A In .Range("A2:A" & LastRow)
If Not IsEmpty(A) Then
ProductCodes(i) = "[Product].[Source Product Number].&[" & A.Value & "]"
i = i + 1
End If
Next A
End With
wksData1.Activate
ActiveSheet.PivotTables("PivotTable7").PivotFields( _
"[Product].[Source Product Number].[Source Product Number]").VisibleItemsList _
= ProductCodes
End Sub
I did try playing around with the on error but having not luck and not finding much online thats specific to my problem
Upvotes: 0
Views: 43