+ Reply to Thread
Results 1 to 10 of 10

Thread: design Pivot Chart Formatting

  1. #1
    Registered User
    Join Date
    06-08-2007
    Location
    Scotland...Lagos...Moscow!
    Posts
    25

    design Pivot Chart Formatting

    Hi all...

    I've just started using pivot tables/charts, but have what is probably a simple problem to fix.

    I formatted the columns on the pivot chart, but when I update the data in the pivot table the formatting of the columns returns to the standard colours - is there any way to make the chart retain my custom column formatting when updating?

    Many Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    268

    Reply

    Hi,

    Your best bet would be to record a macro of you applying your formatting and then incorparate the pivot refresh command into it so that you refresh your pivots using a button (assigning your macro to a autoshape).

    I'll get back to you with some sample code.
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  3. #3
    Valued Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    268

    Reply2

    Heres some code to reresh all pivots in a worksheet, just paste in your recorded macro for applying your format.

    I dont how much you know vba so here goes

    Alt F11 open the editor, down the left hand side drop down menus look for module (if you have not recorded a macro yet - insert >module). There you will be able to put the code. Yor best bet is just to begin with recording a macro of you applying your formatting. Tools > macro etc. It wll record all keystrokes/mouse clicks so be carefull.

    sub name()/ end sub
    - are the beginning/end of your macro so dont delete them.

    just paste the following info in to the macros. depending on what you want.

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim pt As PivotTable
    For Each pt In Worksheets(" The name of your sheet").PivotTables
    pt.RefreshTable
    Next pt
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    or you could reresh your tables then apply formatting macro

    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh 
    ' repeat for all your tables, to find out table numbers record a macro of selecting each one in turn
    Hope it helps (apologies if it does not make sense i'm a little rushed today)
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  4. #4
    Registered User
    Join Date
    06-08-2007
    Location
    Scotland...Lagos...Moscow!
    Posts
    25
    Thanks - I ran the macro for the chart formatting and inserted the code - it does work, but with a caveat - The chart has to be active for it to refresh. If I Ctrl+i to run the macro while in the PivotTable it gives Runtime error 91.

    I'm guessing that because the chart is on a different worksheet and the code starts the last line with 'ActiveChart.ApplyCustomType' it doesn't actually know where to look for it?

    I wish I was about 99% better at VBA than what I am now!

    Thanks

  5. #5
    Valued Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    268

    reply

    Yeah, sorry should have picked up on that.

    try inserting this above the line

     Sheets("Your SheetName").Select
    ActiveSheet.ChartObjects("Your Chart Number").Activate
    hope it helps
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  6. #6
    Registered User
    Join Date
    06-08-2007
    Location
    Scotland...Lagos...Moscow!
    Posts
    25
    Hi...

    Sorry to be so thick, but... ActiveSheet.ChartObjects("Your Chart Number").Activate

    Where do I get the 'chart number' from? What is it referring to exactly?

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    Follow up: I decided it was 'Chart1' from VBA explorer, but when entering this in the "Chart Number" part of the code and then running it, it gives Run Time Error 1004 - Unable to get the chartobjects property of the chart class on this line of code?
    Last edited by DekHog; 07-27-2007 at 04:27 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    268
    Hi,

    No worries, for future reference.

    All charts are automatically given a number during creation to help excel define them in vba etc. So you make a chart on a blank page excel calls it chart 1, you make another excel calls it chart 2 and so on. basically it helps excel reference them. Unfortunalty i dont know if this is limited to my companies version but excel does not allways go in a logical order so you can get chart 1 chart 2 chart 2345 etc. The best way to determine your chart numbers is to record a macro of you selecting them. So start recording your macro click on a blank cell and then click on your charts in an order you can remember, stop recording the macro press alt f11 to open the vba editor and find your macro in the modules and it will have all the chart numbers listed as you selected them.

    now lets have a look at the error

    can you zip and attach the file so i can take a look? dont forget to remove any confidential info ! like figures and replace them with examples.
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  8. #8
    Registered User
    Join Date
    06-08-2007
    Location
    Scotland...Lagos...Moscow!
    Posts
    25
    Hi...

    Thanks for all your time on this - file is attached - code is in the 'Refresh Data' button on the 'Table' worksheet - I've removed 95% of the data, but you can see what's required.
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    268
    Hi,

    edit your code so it looks like this

        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Dim pt As PivotTable
        For Each pt In Worksheets("Table").PivotTables
            pt.RefreshTable
        Next pt
        Application.ScreenUpdating = True
        Application.Calculation = xlCalculationAutomatic
        Sheets("Chart").Select
        ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:= _
                                    "PWB Columns"
    Hope it helps
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  10. #10
    Registered User
    Join Date
    06-08-2007
    Location
    Scotland...Lagos...Moscow!
    Posts
    25
    Works great! Thanks...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0