ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Charts and Charting in Excel (https://www.excelbanter.com/charts-charting-excel/)
-   -   Deleting PivotFields from a PivotChart in VB.NET (https://www.excelbanter.com/charts-charting-excel/134915-deleting-pivotfields-pivotchart-vbulletin-net.html)

Refresher

Deleting PivotFields from a PivotChart in VB.NET
 
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


All times are GMT +1. The time now is 10:03 PM.

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