Deleting PivotFields from a PivotChart in VB.NET

R

Refresher

Hi,
I keep getting an Exception from HRESULT: 0x800A03EC when trying to delete
unneeded PivotFields from my PivotChart. The code I am using is below. Any
thoughts as to why I get an Exception? Any advice on how I can get this to
work?
Thanks.

Dim field As String
Dim pivFields As Excel.PivotFields =
CType(CType(xlWs2.PivotTables("PivotTable1"), Excel.PivotTable).PivotFields,
Excel.PivotFields)

For Each pivField As Excel.PivotField In pivFields
field = pivField.Name
If field <> "Serial Number" And field <> PivotData And field <> PivotRow
And field <> PivotColumn And Not lstXGrouping.Items.Contains(field) And Not
lstSeriesGrouping.Items.Contains(field) Then

For Each pivItem As Excel.PivotItem In pivField.PivotItems
pivItem.Delete()
Next
End If
Next
 

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

Similar Threads


Top