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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,215,390
Messages
6,124,667
Members
449,178
Latest member
Emilou

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