Loss of pivot columns when using pivotcaches.create with new data source

crazyrph

New Member
Joined
Dec 3, 2019
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
I am faced with an issue with my data and pivot table VBA. My data now adds a new blank column on the far left. I must delete this column so that my data fits in the correct range and the column all have a header as before. When I delete this column the range of the source data changes minus the deleted column.
Questions: 1) Is there a way to prevent the data source from changing when deleting the row?
or
2) Is there a way to prevent the following vba from removing the missing columns in the pivot table that are not found in the new data.

ActiveSheet.PivotTables("PivotTable2").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Data2", Version:= _
6)

This line of code seems to remove columns form the pivot for the pivot table field instead of leaving them. I have already ensured the following options are set. (Preserve cell formatting on update - is checked) and (Number of items to retain per field - is set to max) before running the code above. When the code runs it reverts the "Number of items to retain per field" back to automatic and I lose the columns.
I appreciate any and all advice. Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,224,872
Messages
6,181,498
Members
453,047
Latest member
charlie_odd

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