In the following code, it seems that the setting of the .Caption property is being ignored by Excel.
The comments in the code explain what is happening in the workbook.
Doesn't it seem that the .Caption assignment is simply being ignored?
And if so, how could i work around this? Or is the .Caption property simply upsettable within VBA?
(Note: When recording and i change the Caption in the dialog box, what is recorded is the above code using the .Caption property to assign the new Caption.
Thank you if you have any thoughts.
The comments in the code explain what is happening in the workbook.
VBA Code:
ActiveSheet.PivotTables(TabNam).AddDataField ActiveSheet.PivotTables( _
TabNam).PivotFields("Net"), "Sum of Net", xlSum
' Range("BX3").Select
With ActiveSheet.PivotTables(TabNam).PivotFields("Sum of Net")
.Caption = "Cnt"
.Function = xlCount
.NumberFormat = "0"
End With
'The above adds the field 'Net' from the data range and as usual it defaults to using Sum as the Function
'the the With above attempts to change the Function to Count, applies a format, and changes the caption.
'In the table on the sheet, the Function and Format are correctly changed, but the caption is not changed to the assigned Caption.
'The caption on the sheet is 'Count of Net' which is the default caption for the Count Function.
'It seems as though the .Caption assignment is ignored.
ActiveSheet.PivotTables(TabNam).AddDataField ActiveSheet.PivotTables( _
TabNam).PivotFields("Net"), "Sum of Net", xlSum
With ActiveSheet.PivotTables(TabNam).PivotFields("Sum of Net")
.Caption = "Cnt%"
.Function = xlCount
.NumberFormat = "0.0%"
End With
'The exact same thing happens with the above. The Function and NumberFormat are correct on the worksheet.
'But the Caption for this field on the sheet is left at 'Count of Net2'
'Now an even bigger issue occurs, as i try to refer to that field by the Caption I assigned, and VBA breaks with an error.
With ActiveSheet.PivotTables(TabNam).PivotFields("Cnt%")
.Calculation = xlPercentOfColumn
End With
Doesn't it seem that the .Caption assignment is simply being ignored?
And if so, how could i work around this? Or is the .Caption property simply upsettable within VBA?
(Note: When recording and i change the Caption in the dialog box, what is recorded is the above code using the .Caption property to assign the new Caption.
Thank you if you have any thoughts.