+ Reply to Thread
Results 1 to 11 of 11

Return Chart title formula using VBA

  1. #1
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Return Chart title formula using VBA

    Hi

    I have a spreadsheet in which chart titles are linked to the contents of cells through formulas, e.g.

    ='chart data'!$CI$1

    Is there a way to use VBA to return this formula, rather than the text that the formula refers to? All of the ChartTitle properties (caption, text, characters) seem to return the text not the formula. I’m looking for something simple, along these lines:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Return Chart title formula using VBA

    Well, that's just what it is.

    Please Login or Register  to view this content.
    If it does not work for you, please post your code in context.

  3. #3
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Return Chart title formula using VBA

    thanks for that Teylyn

    Unfortunately it didn't work - I don't think formula is a property of ChartTitle or ChartTitle.Text

    here's an example of a sheet with what I'm trying to do - I'd like the macro to return the formula in the chart title:

    =Sheet1!$A$31

    not the content of the cell it refers to:

    "Monthly Australian Dollar Exchange Rates"

    cheers
    Attached Files Attached Files

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Return Chart title formula using VBA

    Well, it works fine in Excel 2010 (see attached screenshot). Maybe there've been some changes in the object model since 2007. I'm not in front of 2007 right now, but I will have a look tomorrow.

    cheers
    Attached Images Attached Images

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Return Chart title formula using VBA

    That's probably it - the code's certainly logical
    sorry, should have mentioned I'm using 2007
    thanks again for your help
    best wishes

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Return Chart title formula using VBA

    Just fired up the machine with XL2007. The property is not available there, and the code bombs.



    Sorry, I don't have a workaround, but I'll ask some of the other members for input.

    cheers,
    Last edited by teylyn; 12-29-2010 at 04:33 AM.

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Return Chart title formula using VBA

    hello again,

    I've asked for input from other members and DonkeyOte gave me a link to www.thecodecage.com where exactly this question was discussed a few months ago.

    In general, it looks like the native 2007 VBA version does not have the property you are after, but the thread in that forum discusses some workarounds by broro183 (who is also active here, and who got a thumbs up for his suggestion by VBA uber-expert Zack Baresse, who is a Microsoft MVP).

    So, maybe you want to hop to http://www.thecodecage.com and check it out:

    http://www.thecodecage.com/forumz/me...rt-titles.html

    cheers,

  8. #8
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Return Chart title formula using VBA

    Hi teylyn

    I can see the work around would be effective, if a bit clunky.

    As I was hoping to use this bit of code on several dozen charts at a time, and the titles are sometimes in different sheets to the charts, I think I'll have to approach it in another way.

    What I was actually trying to do for a worksheet with about 40 charts on was to temporarily delete the chart titles, export the charts as pictures to PowerPoint without titles, put the title text in the title area of the PowerPoint slide, then restore the chart titles (with formula) in the original worksheets. On reflection, I may be able to do this using “Undo” in the Excel code to restore the chart title rather than reinserting the title using the formula.

    Thank you for the sleuthing – at least I didn’t miss anything too obvious.

    Best wishes

    Nicky

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Return Chart title formula using VBA

    Depending upon your charts maybe you could simply change the chart title font colour to match the chart area colour, then export as image.

    Prior to xl2007 the following would have returned the formula for the active chart.
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Return Chart title formula using VBA

    Make sure you also check out the related thread at CodeCage and its link to the full discussion at MrExcel with Jaafar's solution.
    FWIW, I also checked with the MS Excel MVPs and none of them knew of any alternatives, unfortunately.
    Remember what the dormouse said
    Feed your head

  11. #11
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Return Chart title formula using VBA

    thank you all for your help

    All the options for code to return the title formula looked fearsome!

    In the end, I went with a variation of Andy's suggestion - temporarily changing the title font colour to the background colour. I also temporarily set it to font size 1 so it doesn't obscure any axis titles or other material, and resized the plot area to fill some of the space previously used by the chart title.

    if you're interested, here is the code - it copies pictures of all graphs on worksheet "charts" onto PowerPoint slides, and puts the title text in the powerpoint title area. Useful if you're using the same chart pack with lots of charts for multiple purposes.

    You'll need microsoft powerpoint object library checked in tools references

    Please Login or Register  to view this content.

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