Code to Check for Pivot Item

T

T. Jenkins

I have some code that runs through a list of numbers, enters each one in a
page field of a pivot table, then extracts data from each version of that
pivot. Up until recently, this has been working well, but I now have a
situation where one of the numbers I'm using is not in the pivot field, and
Excel is doing some weird stuff by renaming the closest item to the one that
I'm trying to enter.

Bottom line is that I need some code that checks for the existence of each
number before using it as a page field. Can someone please give me some
suggestions on how to do this? I tried running through all items for the
respective pivot field, but for some reason, my simple routine (if pivot item
= my number then run routine, otherwise skip) isn't working.

Appreciate any help.

Thanks,
Todd
 
J

Joel

try this

Found = False
for each item in list
if item = Mynumber then
Found = True
exit for
end if

next item
if Found = True then
'enter your code here
else
'enter your code here
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top