VBA GetPivotData doesn't return a wanted 0

mangelito

New Member
Joined
Nov 16, 2010
Messages
2
Hi
I have this pivot issue that I'd like to have some help with.
I'm using VBA to write a macro that should pick values from a Pivot and put them in a table.

Say for example I am selling clothes. I can get a "Count of Clothes" using:

Code:
iVal = myWorkSheet.myPivot.GetPivotData("Count of Clothes")
This will put, say, 50 in the variable iVal.


I can also filter for shoes:

Code:
iVal = myWorkSheet.myPivot.GetPivotData("Count of Clothes", "Type", "Shoes")
This works great as long as there are shoes in the filtered Pivot. But if there are no shoes, the function seems to return 50 instead of 0.


How do I make the code to return a 0 please?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I suppose there is an "on error resume next"-construction in your macro, otherwise the macro stops on this error.
So if you want 0 after this error, you could make something like this
Code:
on error resume next
......
iVal=0
iVal = myWorkSheet.myPivot.GetPivotData("Count of Clothes", "Type", "Shoes")
 
Upvote 0
I think I got it to work now.
Actually I did use "on error resume next" before, but now I have re-structured the code a bit and it seems to work.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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