Pivot table array - PivotItemExists

Souljacked

New Member
Joined
Jul 15, 2011
Messages
8
Hello,

I have a functioning array that generates dates from a start date to end date. The array is then passed to the pivot table and everything functions correctly.

However occasionally there are dates generated that are not included in my pivot table and when the routine trys to select them I get an error.

What I want to do is when a pivot item does not exist, the routine will just carry on and try to apply the remaining values in the array.

I've tried to read around the subject but so far found no solutions.

Can anyone help?

Code:
'create trade date array
    numDays = enDate - stDate
    
    ReDim dateArr_TradeDate(numDays + 1)
    
    dateArr_TradeDate(0) = "[Trade Date].[Year -  Quarter -  Month -  Date].[Year].&[20" & Right(stDate, 2) & _
    "].&[" & Application.WorksheetFunction.RoundUp(month(stDate) / 3, 0) & "].&[" & (Mid(stDate, 4, 2) * 1) & _
    "].&[20" & Right(stDate, 2) & "." & Mid(stDate, 4, 2) & "." & Left(stDate, 2) & "]"
    
    For x = 1 To numDays
    
    dateArr_TradeDate(x) = "[Trade Date].[Year -  Quarter -  Month -  Date].[Year].&[20" & Right(stDate + x, 2) & _
    "].&[" & Application.WorksheetFunction.RoundUp(month(stDate + x) / 3, 0) & "].&[" & (Mid(stDate + x, 4, 2) * 1) & _
    "].&[20" & Right(stDate + x, 2) & "." & Mid(stDate + x, 4, 2) & "." & Left(stDate + x, 2) & "]"
    
    Next x

Code:
'set trade date criteria
    pt.PivotFields("[Trade Date].[Year -  Quarter -  Month -  Date].[Date]").VisibleItemsList = _
        Array(dateArr_TradeDate())

Cheers,
Souljacked
 
Jerry, If I just want to take a name range (a list of account numbers) and I want to filter by those how to I convert that list into an array?
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello,
The code above works great.

I am trying to modify it slightly to accept a named range with about 208 different zip codes to update the filter.

Currently using the method this is using now I am limited to the 24 line limit in continuous lines so I'd like to use the range.

So far the attempts I've made to insert the named range results in a continuous loop. In this case I've defined a range and made varArrIn:= to that.

My VBA knowledge is very basic still. Any thoughts on how I can take named range in BU1:BU208 and use this code to update on those fields? In addition some of the items in the named range may not exist in the member properties of the Cube.

Thank you,
 
Upvote 0

Forum statistics

Threads
1,217,404
Messages
6,136,416
Members
450,010
Latest member
Doritto305

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top