+ Reply to Thread
Results 1 to 2 of 2

Macro: Creating a chart

  1. #1
    Registered User
    Join Date
    09-18-2011
    Location
    IL
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question Macro: Creating a chart

    Hi,

    I have heard that recording macros and watch the code develop in the VBA window is a great way to develop an intuitive sense on how different things work in the VBA environment. Today, I explored recording a macro on creating graphs. I successfully recorded a macro by creating a box & whisker graph and was amazed to see all the lines of code that were created. Within the first 8 lines that the macro recorded, I gained two thoughts. I was hoping that somebody might clear up my thoughts:
    • First, and unimportantly, I understand a lot of the code is redundant and is not necessarly needed. This thought is unimportant at the moment.
    • Second, and the most important thought is this: Based of the line of code on line 8, this code will not work again if I try to re-run it.


    Please Login or Register  to view this content.

    I went back into Excel, deleted Chart 5, and re-ran the Macro. I hoped my intuition would be wrong and the code would run fine. But my intuition was right and the code crashed. ActiveSheet.ChartObjects("Chart 5").Activate: The problem is here, isn't? Once I deleted Chart 5, and reran the Macro to see if it would work, the Macro didn't have a chart to reference, right?

    So my question is this: If I was to write some code that would create a chart, how would I go about putting in a variable for the chart name? I am not even sure where to begin? Would it look something like this?


    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    09-18-2011
    Location
    IL
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro: Creating a chart

    After a bit more searching through Google, I found my answer!

    http://peltiertech.com/Excel/ChartsH...ameAChart.html

+ 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. Creating a chart with macro fails
    By Wilco88 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-19-2012, 08:35 AM
  2. creating a chart using vba macro
    By tombe in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 11-07-2008, 07:13 AM
  3. Macro creating second chart
    By smorgan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2006, 04:31 PM
  4. [SOLVED] Need help w/ macro creating a chart
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2005, 02:05 PM
  5. [SOLVED] Macro for creating a chart
    By Abhijeet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2005, 08:05 AM

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