+ Reply to Thread
Results 1 to 16 of 16

Using VBA to format Charts and Chart Objects

  1. #1
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Using VBA to format Charts and Chart Objects

    I am using Excel 2013 Charting and I am trying to standardize the formatting across a number of my charts. After I have completed 20 or 30 charts, I find there are inconsistencies across the different type of charts as to font size and type, bolding, thickness of lines, bar chart outlines, chart and axis titles, etc.

    I tried recording a number of macros that would take the active chart or chart object and format everything on it, but they don't work consistently across my charts. I use bar chart macros on bar charts, line chart macros on line charts, etc.

    Some examples of what I would like to accomplish are:
    • All fonts New Times Roman
    • All fonts bold
    • All fonts a minimum of 12 points
    • Color bars that have a black 1.5 point black outline
    • Line charts where all the lines are smoothed and the lines are 1.5 point thickness
    • Outside tick marks on all axis
    • Data labels turned on and oval shapes used with white fill and TNR 12 point bold
    • Chart titles TNR minimum 24 point bold
    • Axis titles TNR 14 point bold

    Would anyone have some code that would at least show me how to access the properties of the active Chart or Chart object. If I could at least address all text and make it TNR 12 point bold, I would be grateful. Given an example of that, I could probably figure out the rest.

    Thanks,

    Tom

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    dont have 2013 but i assume most of the syntax is the same

    Please Login or Register  to view this content.
    this should take care of the first 3

    i dont know exactly what you mean by all fonts as ChartArea encompasses data labels and axis
    any way all the things you said you want all have different syntax...its a matter of trial and error (thru record macro though this is not the best for chart's) or google
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    Thanks humdingaling,

    When I said "all fonts", I was referring to:
    • Chart Title
    • Axis Titles
    • Axis units (both axis)
    • Legend
    • Data Labels

    One thing I was dealing with was how to recognize if the chart is a chart sheet or if the chart is a chart object embedded in the sheet along with data. There seems to be a difference in how you reference each and what properties to use.

    One very frustrating thing I noticed was that if I changed the data labels to ovals (with white fill and black outline), if I had previously formatted the numbers in the data labels, Excel would throw out my previous formatting and I had to start all over. One VBA subroutine I tried to build was to take all data labels on the chart or chart object and make them oval, TNR, 12 point, bold, white fill, black outline and autofitted. I recorded my action on one series but had a problem getting it to work on the other series.

    Here are 4 statements I tried to get my data labels to autosize but none of them would work:

    Please Login or Register  to view this content.
    My ideal goal is to eventually build a subroutine that will go sheet by sheet and apply the above formatting to every chart and chart object so that the entire collection of charts are consistent.

    Any suggestions would for any of the above would be appreciated.

    Thanks,

    Tom

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    using Jon's Peltier method found here
    http://peltiertech.com/apply-chart-f...-other-charts/

    where you select a "master" sheet then run to copy format from then apply to every other chart

    with the amendment he notes for excel version 2007+ fix
    It turns out that

    .Paste Type:=xlFormats
    does not work properly in Excel 2007 onwards. No error appears, but whatever Type is specified, the paste occurs as if you used xlPasteAll.

    The code that works is totally not obvious. Replace the above line with

    .Chart.ChartArea.Select
    ActiveSheet.PasteSpecial Format:=2
    I’d like to talk with the genius who decided PasteSpecial on the ActiveSheet should affect an embedded chart.
    Please Login or Register  to view this content.
    i went with the simple one instead of the bigger one...you can endeavor to try the big version....Copy_Chart_Formats_Not_Titles

  5. #5
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    I tried Jon's vba and it worked but where I had 2 values, I got 4 and all the colors were different. The fonts were cloned, though.

    I went back and tried the subroutine "Copy_Chart_Formats". It errored on "ActiveSheet.PasteSpecial Format:=2" with the error "Object doesn't support this property or method".

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    see the quote i pasted in post #4
    .Paste Type:=xlFormats
    does not work properly in Excel 2007 onwards.
    this is what happens..it duplicates instead of doing it properly

    Re: the error
    was chart selected at time running macro....unable to replicate on my small scale
    unless there is some new bug introduced in excel 2013..im only use 2010 version

  7. #7
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    I am trying this out in 2010 on my home computer. I had the master chart selected when I ran the code.

  8. #8
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    PS. I was using:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    Sorry for the multiple replies. I keep thinking of things to say after I send.

    On Jon's code, where my master chart had 2 series and the target chart has 2 series, the target chart ends up with 4 series after running Jon's code.

  10. #10
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    I didn't read far enough down Jon's blog to see that he revised his code. When I run the following code, it does not double the number of series, however, it only works on Chart Objects, not Chart Sheets. I don't know why.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    as you already know chart objects and chart sheets require different syntax
    which is why i have two loops in the code i posted

    Please Login or Register  to view this content.
    you would need to re-jig the code to run and loop each chart sheet in Activeworkbook
    like the above code

    you will need to remember to declare variable separately
    Please Login or Register  to view this content.
    essentially you are then running two loops one after another with the only linking factor being the copying of formats of original chart

  12. #12
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    humdingaling,

    Thanks for putting me on to Jon's website!

    I just modified Jon's code so that it handles Chart Objects and Chart Sheets. I used a blunt force method of repeating the code for the Chart Objects and modifying it so that handles Chart sheets also.

    Now, if I could figure out how to keep the code from changing the chart type to the same chart type as the master and just format the text in the Titles, data labels and axis units, I would be all set. Any thoughts?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    oh..that slipped my mind...didnt think about different chart types

    maybe
    before apply format changes...retrieve chart type and reapply it after

    so
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    I am not sure how to mark this thread as "solved". I did not see a control that would do it.

  15. #15
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Using VBA to format Charts and Chart Objects

    select Thread Tools from the menu link above and mark this thread as SOLVED

  16. #16
    Registered User
    Join Date
    08-11-2014
    Location
    Washington
    MS-Off Ver
    version 13
    Posts
    14

    Re: Using VBA to format Charts and Chart Objects

    I finally found it. Could it be because the control to mark things "solved" is so hard to find that there aren't more of these threads marked "solved"?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy charts from excel to PPT - unable to re size and format the chart
    By vickybansal99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2014, 12:37 PM
  2. Delink Charts and Objects
    By gdel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2014, 10:00 AM
  3. Hide or unhide charts or objects
    By Karak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 09:23 AM
  4. [SOLVED] VBA to copy/paste chart format to all other charts in workbook
    By rarnett in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2012, 09:12 AM
  5. Macro to delete all objects except charts
    By Mathematicus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2011, 03:12 PM
  6. insert excel charts as objects
    By mcarrington in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 01-07-2006, 01:00 AM
  7. [SOLVED] Draw Objects in Charts
    By Mike Hogan in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-06-2005, 09:05 AM

Tags for this Thread

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.6.0 RC 1