Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Excel VBA Question

Status
Not open for further replies.

Adamba

IS-IT--Management
Aug 3, 2001
72
GB
[wavey] Hiya!

I have been coding an automated system of creating Pivot tables and colouring certain lines on the report in VBA.

I have managed to Create a document with accurate pivot tables and coloured the required lines. The problem i am getting is that when the data is refreshed on the pivot table the colourings that my code put in dissapear. I have tried setting up my code to create pivot tables which "Preserve Formatting" but still any 'coded' colours are lost on refresh. if i manually add colours to the pivot they stay there even when the data has been refreshed.[wiggle]

Can Visual Basic on do 'Cosmetic' Changes to the pivot tables or am i missing something in the code below. The code below is just the pivot creation section. I add the colours later on in my prog.

I would greatly appreciate any help with this, as its starting to do my head in. Good ole Microsoft!
[rofl]

Thanks In advance! [thumbsup2]

Sorry ive tried to tidy it up a bit
Code Extract:

ActiveSheet.PivotTableWizard SourceType:=xlPivotTable, SourceData:= _
"[" & Retailer & " " & Category & " DATA.XLS]£,U,D by Month!PivotTable1", TableDestination:="", _
TableName:="PivotTable2"
ActiveSheet.PivotTables("PivotTable2").PivotFields("SubCat").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Type").Subtotals = Array(
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Flavour").Subtotals = Array _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Description").Subtotals = _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").PivotFields("Size").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("SubCat", _
"Description", "Type", "Flavour", "Size"), ColumnFields:="Wk Ending Date"
With ActiveSheet.PivotTables("PivotTable2")
.ColumnGrand = False
.RowGrand = False
.HasAutoFormat = False
.PreserveFormatting = True
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Value")
.Orientation = xlDataField
.Name = "Value "
.NumberFormat = "£#,##0.00"
End With
[pc3]
Adam [glasses]
 
You must turn the "Autoformat Table" property to false and have enableselection = TRUE
on your pivot table options to keep formatting
HTH Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top