+ Reply to Thread
Results 1 to 9 of 9

Macro to draw a Line Graph

  1. #1
    Registered User
    Join Date
    08-26-2010
    Location
    Halden, Norway
    MS-Off Ver
    Excel 2007
    Posts
    27

    Macro to draw a Line Graph

    Hi all,

    I would like to draw an line graph.

    In Row 4 I have = C4 : G4 = the values 2009 2008 2007 2006 2005

    In Row 5 I have = C5 : G5 = the values 0,5 1,3 -2,5 3,4 6,5

    I would like to draw a Line graph where (create a Macro)

    the x-axis = C4 : G4
    the y-axis = C5 : G5

    I have tried to use some the examples in this Forum, but with no luck.

    Please help.

    Regards,
    Last edited by jmadsen; 09-02-2010 at 04:48 AM.

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

    Re: Macro to draw a Line Graph

    I used the marco recorder to get the following.

    Please Login or Register  to view this content.
    If the values in C4:G4 are numeric then the chart will probably contain 2 lines and default axis labels. This is because Excel guessed the year values where actual another data series.
    You can avoid this by making the cells text by entering a single quote before the value, example '2009
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-26-2010
    Location
    Halden, Norway
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Macro to draw a Line Graph

    I have found this code.

    Please Login or Register  to view this content.
    This code only stacks the values vertically.

    I have attached a .jpg on how I would like the result to be.

    Please advice...

    Regards,
    Attached Images Attached Images

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

    Re: Macro to draw a Line Graph

    Did you try using the macro recorder?
    Did you try the code example I posted?

  5. #5
    Registered User
    Join Date
    08-26-2010
    Location
    Halden, Norway
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Macro to draw a Line Graph

    Hi Andy,

    Your example worked fine and Your advice regarding using the macro-recorder
    was excellent. This is helpfull when I need to know the code for properties for
    the objects.

    I hope to be able to make a macro I can re-use. I would like to just
    send parameters to the procedure and then it generates a graph.
    The parameters would be the Range and the type of graph.

    Regards,

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

    Re: Macro to draw a Line Graph

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-26-2010
    Location
    Halden, Norway
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Macro to draw a Line Graph

    So simple . Thanks alot Andy.

  8. #8
    Registered User
    Join Date
    10-16-2012
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro to draw a Line Graph

    i have a query over here what if my data keeps increasing as in if i have a data from a1 to az5 today and then tomorrow i have data from a1 to bc5 how do i get a chat correct without grand total

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to draw a Line Graph

    Achirag,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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