mikekingtx
New Member
- Joined
- Jan 7, 2014
- Messages
- 2
I'm a .Net developer and it's obvious I'm not grasping the Pivot Table correctly. I've written code to create a sum of values based on a worksheet. Specifically:<br>Location<br>ID<br>Dept<br>Sum of Hours Worked. Location, ID and Dept are rows. This effectively provides the aggregate values that I need based on the row groupings.<br><br>Here's where this is falling apart. I need to create a new worksheet based on these values. I assumed the three row values - Location, ID and dept - would be in a hierarchy. It's possible they are, I just can't figure out the object model.<br><br>When I loop through the PivotItems collection of the PivotFields("Location"), I get what I need. However, I'm unable to determine how to loop through the child values (just for that location). PivotFields("ID") returns all IDs. I can't figure out how to return only the child entries for each pivot item. GetPivotData hasn't been very useful for this. As far as I can tell, GetPivotData, while its return type is listed as Range, throws an error when more than one cell is returned. Worst case, I suppose I can just parse the data in the DataBodyRange of the pivot table - maybe not, I haven't tried that. I'm hoping there's a way to iterate through these collections, but based on what I've seen from Google searches, there may not be. Does my pivot table need to be rearranged? I suppose I could also just dump this data into a data table - that may be my final solution, although I'm not sure how much support VBA has for that. Unfortunately, at least for me anyway, this data must remain in Excel.<br>Thanks in advanced for any advice.<br>-- Mike