ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to Check for Pivot Item (https://www.excelbanter.com/excel-programming/398501-code-check-pivot-item.html)

T. Jenkins

Code to Check for Pivot Item
 
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


joel

Code to Check for Pivot Item
 
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

"T. Jenkins" wrote:

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



All times are GMT +1. The time now is 05:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com