Pivot Table run-time error 1004 (PivotField class)
Just posting back on my findings. I tried many of the variations that
were in that link, and the closest I got was to actually get the pivot
table to quickly filter on my catalog number variable. However, it
left the attached slicers untouched. And several things I tried on
the slicers worked, but every option took an inordinate amount of
time. That's presumably because of the 300+ pivot items the code is
looping through.
I'm able to use .ClearAllFilters to reset everything, so it would be
nice if I was able to .AddAllFiltersExcept without doing a loop, but I
don't think that exists. It should, though, because there are about a
zillion posts out there from people like me looking for something very
similar.
I think I've hit a dead end. Any other thoughts or possibilities?
Thanks Garry (and anyone else).
Frank
On Sat, 07 Apr 2018 15:52:06 -0400, Phrank wrote:
On Sat, 07 Apr 2018 15:33:02 -0400, GS wrote:
Thanks Garry. I haven't had a chance to look at the C++ in the link
yet. Will do that tonight.
There's no C++ at the link; -it's pure Excel and/or VBA samples/examples about
working with PivotTables.
In the meantime, I recorded the macro,
and below is an excerpt of what it returns. There are actually over
300 items in the list. So, the macro above is looping through each of
those items, as the code below more or less is doing, but the code
above takes about 45 seconds to load, whereas the recorded code below
is almost instantaneous. Is there not a way to turn off all the
slicer items at once, and then turn on just the one I need? That's
what I've been looking for but have not been able to find. Thanks
Garry.
Sub Macro1()
With ActiveWorkbook.SlicerCaches("Slicer_Catalog")
If mySlicerItem = .SlicerItems("277096275") Then .Selected =
True
.SlicerItems("277096276").Selected = False
.SlicerItems("277096325").Selected = False
.SlicerItems("1100000000").Selected = False
.SlicerItems("1900013000").Selected = False
.SlicerItems("1900031000").Selected = False
.SlicerItems("2108100000").Selected = False
.SlicerItems("2108105000").Selected = False
.SlicerItems("2108151000").Selected = False
.SlicerItems("2108352000").Selected = False
.SlicerItems("2296003108").Selected = False
.SlicerItems("2296003111").Selected = False
.SlicerItems("2296003125").Selected = False
.SlicerItems("2296003511").Selected = False
.SlicerItems("2296301000").Selected = False
End With
End Sub
Have you looked in the ObjectBrowser to see what properties/methods a
PivotTable exposes to VBA?
Hi Garry,
Sorry, I misunderstood about the link. I just looked at it, and wow!
There is a lot of pivot table stuff in there! I'm going through it
now and have found a few things that might work. I'll follow-up here
and let you know what I come up with.
Regarding your last comment about the ObjectBrowser, I did not think
to do that. I'll plug away tonight and take a look there too.
Thanks Garry. Back at you soon.
|