+ Reply to Thread
Results 1 to 7 of 7

I can't integrate graph with macro

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    I can't integrate graph with macro

    I have a problem creating a graph and integrating it with a macro.
    I hope somebody can show me how to do it.

    I attached two xlsm files to illustrate my problem. Both Excel files contain an identical macro. The macro creates a new workbook and generates a table of random data.

    The file WithGraph.xlsm has a graph. This is the positive control. The graph does what it is supposed to do. That is allowing the user to scroll up and down through the data. In the NoGraph.xlsm file I deleted the graph. I tried to recreate it but I failed.

    First question:
    How do I recreate this graph?

    Second question:
    Is there a way to use a macro to create this graph?
    Attached Files Attached Files
    Last edited by dschmitt; 10-15-2010 at 03:40 AM.

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

    Re: I can't integrate graph with macro

    Your macro does not have any code to create a chartobject.
    It simple uses the existing chart. If the chart does not exist or it have a different name the code will fail.

    Please Login or Register  to view this content.
    I guess you need to check the sheet for a chartobject and then if not present add one.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: I can't integrate graph with macro

    Yes, you are correct, WithGraph.xlsm uses an existing chart, there is no code to create a chart.

    The problem I have is that I can not manually recreate the graph in WithGraph.xlsm after I have deleted it and before executing the macro. In other words, open WithGraph.xlsm, delete the chart, recreate it and then execute the macro. I have a conceptual problem there. What chart settings do I need to choose so that the new chart will tie into the existing code that tells the chart what to display? Once that problem is solved then I can add a code to NoGraph.xlsm to create the chart and set the right chart settings.
    Last edited by dschmitt; 10-13-2010 at 07:48 PM.

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

    Re: I can't integrate graph with macro

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: I can't integrate graph with macro

    great, Andy. Exactly what I was looking for.

    One last question. Can you describe why the below script is needed.
    Please Login or Register  to view this content.
    I speculate that when a chart is created it creates its own object In order to make the new chart use the Sheet1(Ranking) Object script the object that was created with the chart needs to be deleted.

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

    Re: I can't integrate graph with macro

    That code removes any series created automatically when the chartobject is added.

  7. #7
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: I can't integrate graph with macro

    OK, thanks. Now I understand.

+ 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